我正在尝试在 android 中创建一些可点击的图像来填满屏幕的宽度,但可点击表面的高度与图像本身的高度相匹配。
我有以下代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image1"
android:onClick="onClick2" />
</RelativeLayout>
到目前为止发布的答案都没有帮助我,FitXY
没有帮助,因为我想保留纵横比。关于图像按钮或更改比例类型的其他答案给我完全相同的问题。
最佳答案
需要的标签是android:adjustViewBounds="true"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height = "fill_parent" android:layout_width = "fill_parent">
<ImageView
android:layout_width = "wrap_content"
android:adjustViewBounds="true"
android:layout_height = "wrap_content" android:id = "@+id/ImageView1"
android:src = "@drawable/ic_launcher"/>
<ImageView android:layout_width = "wrap_content"
android:layout_height = "wrap_content" android:id = "@+id/ImageView2"
android:src = "@drawable/ic_launcher"
android:adjustViewBounds="true"
android:layout_below = "@+id/ImageView1"/>
</RelativeLayout>
关于android - 匹配屏幕宽度和图像高度的可点击图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24428765/