'Align image within imageView to bottom center
I have a simple imageView and I want an image to be displayed in the center of the bottom. At the moment it is displayed in the bottom right corner.
<ImageView
app:srcCompat="@android:drawable/simple_picture"
android:id="@+id/picture"
android:layout_centerHorizontal="true"
android:layout_height="300dp"
android:layout_width="330dp"
android:scaleType="fitEnd"/>
is there any way to use scaleType for bottom and center?
Thank you!
Solution 1:[1]
Add parent layout as Relative
<ImageView
android:id="@+id/picture"
android:layout_width="250dp"
android:layout_height="350dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
app:srcCompat="@drawable/oldman1" />
Solution 2:[2]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:gravity="bottom|center">
<ImageView
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_chat" />
</LinearLayout>
Add another view as parent
Solution 3:[3]
You can take RelativeLayout as a parent layout and set in ImageView
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
try this ...
Solution 4:[4]
Look at answer for similar question. I think, using android:scaleType="matrix"
can resolve problem.
Solution 5:[5]
If parent is linear layout then try :
android:layout_gravity="center"
If parent is relative layout then use :
android:layout_centerHorizontal="true"
Solution 6:[6]
I know from this question 5 years ago But I wanted to help others You do [[ NOT NEED TO USE scaleType ]] my friend
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center">
<ImageView
android:id="@+id/myimageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@drawable/MyImage" />
</RelativeLayout>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Bincy Baby |
Solution 3 | aj0822ArpitJoshi |
Solution 4 | Community |
Solution 5 | |
Solution 6 | Bad Boy |