【问题标题】:How to set ImageView align to parent bottom and scaleType如何设置 ImageView 对齐到父底部和 scaleType
【发布时间】:2018-06-28 11:06:30
【问题描述】:

我正在尝试将图像与其父级底部对齐。基本思想是使图像适合屏幕宽度,使用wrap_content 作为高度,然后将所有内容与父级底部对齐。不幸的是,结果是底部有 1-2dp 的边距,我无法摆脱。我在这里将父母的背景更改为蓝色,所以很明显:

<RelativeLayout
    android:layout_gravity="center_horizontal"
    android:id="@+id/contentView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

   <ImageView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:adjustViewBounds="true"
       android:scaleType="centerCrop"
       android:src="@drawable/top_graphic" />
//...
</RelativeLayout>

这是布局构建器中的样子:

底部的那条蓝线我无法摆脱。我不想直接使用dp 值,我该如何解决这个问题?

【问题讨论】:

    标签: android android-imageview android-relativelayout android-wrap-content


    【解决方案1】:

    试试这个

    <ImageView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentBottom="true"
          android:adjustViewBounds="true"
          android:scaleType="fitXY"
          android:src="@drawable/top_graphic" />
    

    【讨论】:

    • 不幸的是相同的结果。到目前为止唯一有效的是设置负边距
    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多