ImageView adjustViewBounds在fitXY下不起作用

4
我使用以下代码来显示我的按钮:
(因为我需要在按钮上添加文本,所以我不会使用ImageButton)
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/bottom001"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"/>
</RelativeLayout>

但是ImageView在视图中会有一些空白区域

我认为"fitXY"会填充视图,但实际上并没有

bottom

我在这种情况下该怎么办?

谢谢你的帮助 :)


这是因为您将图像调整为适合整个ImageView,那么调整边界如何工作呢..伙计。 - Reprator
谢谢,但我需要按钮填充整个宽度.....并且高度按比例缩放。 - 陳家錡
1个回答

1

设置 android:layout_width="wrap_content" 并使用 LinearLayout

最后

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/test"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"/>

详情请阅读 android-imageview-scaletype-samples

FIT_XY

使用FILL缩放图像。在可用的宽度和高度内拉伸图片,忽略纵横比。


1
但是我需要ImageView填满宽度,应该怎么做? - 陳家錡
等一下,在这里我正在测试。 - IntelliJ Amiya
上帝啊,对不起,我觉得这是我的图片的问题。 - 陳家錡
1
非常抱歉,这个空白区域是用来放置阴影的。 - 陳家錡
1
由于从UI设计师那里得到的图片。 - 陳家錡
显示剩余4条评论

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