How can I align an image inside an ImageView to the bottom of the ImageView?
Asked Answered
A

4

14

I want the drawable inside my ImageView to be shown aligned to the bottom (of the Imageview), and not centered.

Is it possible to do that?

Asphalt answered 31/8, 2011 at 11:29 Comment(0)
U
48

Maybe this is too late, but even I ran into the same problem today and fixed it by using the following snippet.

All the alignment/scaling options are in the scaleType attribute.

Now, if you want to align the image with the beginning of the ImageView, use android:scaleType="fitStart".

Similarly, android:scaleType="fitEnd" to align it with the bottom of the ImageView.

Unfamiliar answered 25/8, 2014 at 11:7 Comment(1)
fitStart put image in top-left corner and fitEnd put in bottom-right corner. But what if you want image at bottom-center? For that Fresco provides custom scalType.Stome
Y
2

You can wrap the ImageView inside a FrameLayout and align using android:layout_gravity like this:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|bottom"
            android:src="@drawable/img_select_profile" />
</FrameLayout>
Youngling answered 1/12, 2017 at 18:44 Comment(0)
L
0

If you have SVG you can open it in https://boxy-svg.com/app or any other online svg editor

Align Image Bottom.

enter image description here

Latium answered 13/8, 2021 at 16:47 Comment(1)
For me, this helped. My svg had blank space at bottom. Without clipping that, none of other options worked.Squama
F
-2

You'll have to set the weight of it to 1 or set its alignment to bottom.

http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html

Fist answered 31/8, 2011 at 11:30 Comment(3)
it doesn't seem to work. That method align the entire imageview to the bottom of LinearLayout. But i want that the drawable aligned to the bottom of the ImageViewAsphalt
OK, then how about setting android:layout_alignParentBottom="true" in the XML instead?Fist
I still have the same problem.Asphalt

© 2022 - 2024 — McMap. All rights reserved.