I have an ImageView with max height and max width both set to 100. The figure below is clearly not a square, but you can use your imagination ;)
Figure 1:
╔══════════════════════════════════════════════╗
║ ImageView ╔══════════════╗ ║
║ ║ ║ ║
║ ║ Actual image ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ║ ║ ║
║ ╚══════════════╝ ║
╚══════════════════════════════════════════════╝
Anyway, If I try to set a BitMap to the ImageView that does not have a ratio of 1:1, the image is positioned like pictured in Figure 1. What I want is for the picture to be placed to the left inside the ImageView like pictured in Figure 2 below.
Figure 2:
╔══════════════════════════════════════════════╗
║══════════════╗ ║
║ ║ ║
║ Actual image ║ ║
║ ║ ║
║ ║ ║
║ ║ ║
║══════════════╝ ║
╚══════════════════════════════════════════════╝
You can see my ImageView in XML below. maxHeight, maxWidth and adjustViewBounds are set during runtime.
<ImageView android:id="@+id/someImage"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textName"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingRight="4dp"
/>
This is in a RelativeLayout if it makes any difference.
If you're working with an Android application, this source code works as a way to load an image from a file: Bitmap bitmap = BitmapFactory. decodeFile(pathToPicture);
An ImageView control is used to display images in Android applications. An image can be displayed by assigning it to the ImageView control and including the android:src attribute in the XML definition of the control. Images can also be dynamically assigned to the ImageView control through Java code.
If you want to just fit the image in image view you can use" wrap content" in height and width property with scale-type but if you want to set manually you have to use LayoutParams. Layoutparams is efficient for setting the layout height and width programmatically.
try this
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_icon"
android:scaleType="fitStart"/>
It just helps for me.
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