I have two ImageViews as belows :
<ImageView android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<ImageView android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
/>
the first imageView displays image in its actual size, the second ImageView should displays image in fitCenter size.
I have been trying this code :
ImageView img1 = (ImageView) findViewById(R.id.image1);
ImageView img2 = (ImageView) findViewById(R.id.image2);
img2.setImageDrawable(img1.getDrawable());
but the second ImageView just displays image as the first one. Yes, in its actual size.
Can anyone help to find the solution?
Thanks
Set different image inside imageview on button click dynamically in android app. Imageview image can be easily replaceable through MainActivity.java coding file because sometimes app developer want to change the imageview image on any button click. So here is the complete step by step tutorial for Change image in imageview programmatically android.
AnyClass.Application of ImageView is also in applying tints to an image in order to reuse a drawable resource and create overlays on background images. Moreover, ImageView is also used to control the size and movement of an image. Whenever ImageView is added to an activity, it means there is a requirement for an image resource.
Select the path of the image file on your computer and click “ OK “. After that set, the “ Qualifier type ” and “ value ” of the image file according to your need and click “ Next ” then “ Import “. Drag the ImageView class in the activity area, a pop-up dialogue box will appear which contains your imported image file.
ImageView class or android.widget.ImageView inherits the android.view.View class which is the subclass of Kotlin. AnyClass.Application of ImageView is also in applying tints to an image in order to reuse a drawable resource and create overlays on background images. Moreover, ImageView is also used to control the size and movement of an image.
You can try something like this:
ImageView img2 = (ImageView) findViewById(R.id.image2);
img2.setScaleType(ImageView.ScaleType.CENTER_CROP);
img2.setImageDrawable(img1.getDrawable());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With