Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ImageButton:强制方形图标(高度= WRAP_CONTENT,宽度=?)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的水平LinearLayout中,我有一个TextEdit和一个 ImageButton. ImageButton与TextEdit一样高.

我希望ImageButton的长度和它一样宽.

目前看起来ImageButton的宽度就像没有缩放时一样(ImageButton width [px] =未缩放的可绘制宽度[px]):

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

    <EditText
        android:id="@+id/txtName"
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/btSet"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:scaleType="fitEnd"
        android:src="@drawable/pin2" />

</LinearLayout>

它应该如何:

解决方法

试试这个,我认为这应该有效:
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/btSet"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentright="true"
        android:scaleType="centerInside"
        android:adjustViewBounds="true"
        android:src="@drawable/pin2" />

    <EditText
        android:id="@+id/txtName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toLeftOf="@id/btSet" />

</RelativeLayout>

解释:centerInside将确保图像在ImageButton的范围内按比例缩放. adjustViewBounds =“true”将…好吧,调整视图的边界,如果图像需要缩放.

大佬总结

以上是大佬教程为你收集整理的android – ImageButton:强制方形图标(高度= WRAP_CONTENT,宽度=?)全部内容,希望文章能够帮你解决android – ImageButton:强制方形图标(高度= WRAP_CONTENT,宽度=?)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。