android - 如何调整 ImageButton 的宽度和高度?

标签 android xml imagebutton

我一直在寻找这个问题的答案,但找不到适合我的答案。 我想在线性布局中将三张图片放在同一行。我希望它们成为 ImageButtons,这是我的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageButton
        android:id="@+id/ImageButton05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scaleType="centerInside"
        android:src="@drawable/background" />

    <ImageButton
        android:id="@+id/ImageButton04"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scaleType="centerInside"
        android:src="@drawable/background" />

    <ImageButton
        android:id="@+id/ImageButton03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scaleType="centerInside"
        android:src="@drawable/background" />

</LinearLayout>

我遇到的问题是,由于图片“背景”太大,按钮的粗细显示正确,而高度却比预期的大很多。 它看起来像这样:

looks http://imageshack.us/a/img18/1516/x3qi.png

它应该是这样的:

should look http://imageshack.us/a/img855/834/403t.png

如何在不指定 dp 大小的情况下解决这个问题?

最佳答案

只需将 android:adjustViewBounds="true" 添加到您的每个 ImageButtons。这就是您所需要的。

关于android - 如何调整 ImageButton 的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18550429/

相关文章:

android - 如何在 RelativeLayout 中设置 fragment 在中心的位置

java - 如何查找 testng.xml 文件中正在执行的测试数量

xml - 在 Go 中使用交替内容类型解码 XML 元素

xml - 使用 Microsoft.xmldom 更改 XML 元素的命名空间前缀以利用 GetElementsByTagName

android - 如何使ImageButton每次单击时重复播放声音

android - 如何覆盖 Google Play 服务的权限要求?

android - 如何使用 Android 设备 3.5 毫米耳机插孔读取/发送数据?

android - 我怎样才能在android中拖动一个图像按钮

android - 在 ImageButton 中拉伸(stretch)图像时遇到问题

java - 如何使用 OpenTok 收听来 self 的应用程序的传入视频通话?