4

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!

Patel Pinkal
  • 8,984
  • 4
  • 28
  • 50
Yuppie
  • 41
  • 1
  • 3
  • 1
    Possible duplicate of [Android image view matrix scale + translate](http://stackoverflow.com/questions/6075363/android-image-view-matrix-scale-translate) – Sergei Bubenshchikov Dec 29 '16 at 05:08

6 Answers6

2

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" />
0
<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

Bincy Baby
  • 3,941
  • 5
  • 36
  • 62
0

You can take RelativeLayout as a parent layout and set in ImageView

    android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"

try this ...

aj0822ArpitJoshi
  • 1,142
  • 1
  • 9
  • 25
0

Look at answer for similar question. I think, using android:scaleType="matrix" can resolve problem.

Community
  • 1
  • 1
Sergei Bubenshchikov
  • 5,275
  • 3
  • 33
  • 60
0

If parent is linear layout then try :

android:layout_gravity="center"

If parent is relative layout then use :

android:layout_centerHorizontal="true"
Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37
0

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>