gpt4 book ai didi

android - match_parent 破坏完整布局

转载 作者:行者123 更新时间:2023-11-30 01:31:47 28 4
gpt4 key购买 nike

我有一个带有 ImageButton 的布局。我现在要做的是将一个 TextView float 在那个 ImageButton 的角落。我将 ImageButton 替换为:

    <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:padding="5dp"
android:text="12"
android:textColor="@color/white"
android:id="@+id/textView5"
android:background="@drawable/textview_notify"
android:layout_column="2"/>
<ImageButton
android:id="@+id/btnInspect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="inspect"
android:onClick="btnInspect_onClick"
android:contentDescription="@string/inspect"
android:src="@drawable/inspect" />
</RelativeLayout>

但是,当 ImageButton 设置为 android:layout_wdith="wrap_content" 时,我可以在视觉 View 中看到 RelativeLayout的宽度是我想要的,ImageButton 只填充其中的一部分。

我估计将它设置为 match_parent 会完全填满它。相反,它破坏了完整的布局。所有元素(此 View 中有更多元素)都消失了。

如何在布局中用 RelativeLayout 替换 ImageButton

最佳答案

为什么不直接将图像作为可绘制对象添加到您的 TextView 中?像这样

   <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:padding="5dp"
android:text="12"
android:textColor="@color/white"
android:id="@+id/textView5"
android:background="@drawable/textview_notify"
android:drawableLeft="@drawable/inspect"
android:layout_column="2"/>

这将是一种资源效率更高的方式,因为您使用的浏览量更少

关于android - match_parent 破坏完整布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35654619/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com