Step 1: Create a new project and name it ImageViewExample. And whenever user click on an image Animal name is displayed as toast on screen. In below example code we set the value for scale type “fitStart” which is used to fit the image in the start of the image view as shown below: īelow is the example of imageview in which we display two animal images of Lion and Monkey. Let’s we take an another example of scale type to understand the actual working of scale type in a image view. The value for scale type attribute can be fit_xy, center_crop, fitStart etc.īelow is the example code of scale type in which we set the scale type of image view to fit_xy. scaleType:scaleType is an attribute used to control how the image should be re-sized or moved to match the size of this image view. īelow is the example code of padding attribute in which we set the 30dp padding from all the side’s of a image view. ![]() padding: set the padding from the all side’s of the image view.paddingBottom: set the padding from the bottom side of the image view.paddingTop: set the padding from the top side of the image view.paddingLeft: set the padding from the left side of the image view.paddingRight: set the padding from the right side of the image view.padding: padding attribute is used to set the padding from left, right, top or bottom of the Imageview. tBackgroundColor(Color.BLACK) //set black color in background of a image view in java classĤ. ImageView simpleImageView=(ImageView) findViewById(R.id.simpleImageView) *Add in Oncreate() funtion after setContentView()*/ In below example code we set the black color in the background of a image view. We can also set the background at run time programmatically in java class. We can set a color or a drawable in the background of a ImageView.īelow is the example code in which we set the black color in the background and an image in the src attribute of image view. background: background attribute is used to set the background of a ImageView. ImageView simpleImageView=(ImageView) findViewById(R.id. For that we use setImageResource() method as shown in below example code. We can also set the source image at run time programmatically in java class. ![]() Below is the example code in which we set the source of a imageview lion which is saved in drawable folder.
0 Comments
Leave a Reply. |