android - ImageView adjustViewBounds 不适用于 fitXY

标签 android button imageview scaletype adjustviewbounds

我使用下面的代码来显示我的按钮

(因为我需要在按钮上添加文字,所以我不会使用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在View中会有一些空白区域

我认为“fitXY”会填充 View ,但它没有

bottom

遇到这种情况我该怎么办?

感谢您的帮助:)

最佳答案

设置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 缩放图像。在可用宽度和高度内拉伸(stretch)图片,忽略纵横比。

关于android - ImageView adjustViewBounds 不适用于 fitXY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31785847/

相关文章:

java - android 尝试乘法和显示 double 时出现错误

c# - 单击事件处理程序 : Method Name Expected and other Errors

button - NetLogo: "stop"不能永远从另一个程序按钮吗?

android:通过 picasso 从网络加载按钮背景图像

java - android - 将图像保存到画廊

java - Android Studio 的约束布局无法正常工作

android - 共享偏好 Facebook

安卓 FileNotFoundException res/drawable-hdpi/scrollbar_handle_vertical.9.png

sorting - 客户端 graphQL 排序 - 可以添加一个将 graphql 查询排序从 ASC 反转为 DESC 的按钮吗?

multithreading - 在后台和线程中加载 JavaFX 图像