【问题标题】:Align image within imageView to bottom center将 imageView 中的图像与底部中心对齐
【发布时间】:2016-12-29 04:53:48
【问题描述】:

我有一个简单的 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?

谢谢!

【问题讨论】:

标签: android xml imageview android-imageview scaletype


【解决方案1】:

将父布局添加为相对

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

【讨论】:

    【解决方案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>
    

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

    【讨论】:

      【解决方案3】:

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

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

      试试这个...

      【讨论】:

        【解决方案4】:

        查看answer 了解类似问题。我认为,使用android:scaleType="matrix" 可以解决问题。

        【讨论】:

          【解决方案5】:

          如果父级是线性布局,那么试试:

          android:layout_gravity="center"
          

          如果父级是相对布局,则使用:

          android:layout_centerHorizontal="true"
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-04-05
            相关资源
            最近更新 更多