我有一个ImageButton
的布局。我现在想要做的就是把TextView
浮在ImageButton
的角落里。我用这个代替ImageButton
:match_parent破坏完整的布局
<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"
,我可以在视觉视图看到RelativeLayout
的宽度是我怎么想的那样,与ImageButton
填充只是其中的一部分那个。
我认为将其设置为match_parent
会完全填满它。相反,它会破坏整个布局。所有元素(在这个视图中更多)都消失了。
如何在我的布局中将ImageButton
替换为RelativeLayout
?
也许Framlelayout将会更好用于你的使用 – Chol
@Chol你是对的。这工作。我仍然可以在那里的任何地方浮动'TextView'吗? –
我的提示:与其使用包含ImageView和TextView的RelativeLayout,包含**复合可绘制**的单个TextView更高效(1个视图对1个ViewGroup和2个视图)。 –