我需要在 ImageView 中间放置一个 TextView ,所以我有这段代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/menu_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1" />
<ImageView
android:id="@+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginBottom="@dimen/menu_icon_margin_top_bottom"
android:layout_marginRight="@dimen/menu_icon_margin_right"
android:layout_marginTop="@dimen/menu_icon_margin_top_bottom" />
<TextView
android:id="@+id/notif_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/menu_icon"
android:layout_alignLeft="@id/menu_icon"
android:layout_alignRight="@id/menu_icon"
android:layout_alignTop="@id/menu_icon"
android:lines="1"
android:text="69"
android:textColor="@android:color/white" />
我需要最后一个 textview 始终位于 menu_icon ImageView 的中心,但我的方法不起作用,它只是将它放在左上角。
最佳答案
由于您的 ImageView 没有填充所有 RelativeLayout,您无法达到理想的效果。我建议您将 ImageView 和 TextView 放在 FrameLayout 中。
<FrameLayout
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true">
<TextView
android:id="@+id/menu_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1" />
<ImageView
android:id="@+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/menu_icon_margin_top_bottom"
android:layout_marginRight="@dimen/menu_icon_margin_right"
android:layout_marginTop="@dimen/menu_icon_margin_top_bottom" />
</FrameLayout>
关于android - 在 imageview android 中间插入一个 textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14666106/