将图像在imageView中底部居中对齐

4

我有一个简单的imageView,想要将一张图片显示在底部中央。目前它被显示在了底部右侧角落。

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

有没有办法同时使用底部和中心的scaleType呢?谢谢!

1
可能是Android ImageView矩阵缩放+平移的重复问题。 - Sergei Bubenshchikov
6个回答

2

将父布局设置为相对布局

<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

看看答案中是否有类似的问题。我认为,使用android:scaleType="matrix"可以解决问题。


0

我知道这个问题是5年前的了 但我想帮助其他人 我的朋友,你不需要使用scaleType

<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>

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>

将另一个视图作为父级添加


0

你可以将RelativeLayout作为父布局,然后在ImageView中设置

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

试试这个...


0
如果父布局是线性布局,则尝试以下操作:
android:layout_gravity="center"

如果父布局是相对布局,则使用以下代码:

android:layout_centerHorizontal="true"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接