【发布时间】:2013-10-04 22:54:21
【问题描述】:
下图是我想要达到的最终结果:
到目前为止,我的代码在将按钮居中对齐方面效果很好:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageButton
android:id="@+id/button_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_border"
android:layout_marginTop="25dp"
android:src="@drawable/categories" />
<ImageButton
android:id="@+id/button_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button_A"
android:layout_marginLeft="34dp"
android:layout_marginTop="25dp"
android:background="@drawable/my_border"
android:src="@drawable/shopping_cart" />
</RelativeLayout>
然后,在“button_B”之后,我尝试实现消息“TEXT HERE IN CENTER”但没有成功。
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TEXT HERE IN CENTER"/>
</RelativeLayout>
有什么想法吗?谢谢。
编辑:已解决。 http://pastebin.com/9DwaQrPq
【问题讨论】:
-
根据这个布局的其余部分应该做什么,你真的不需要两个相对的布局。所以你根本没有得到文本,或者它没有居中?
-
@Sualkcin 它没有居中,如果我像帖子中所说的那样放置 textview,则图像按钮不会居中。
标签: android xml eclipse android-relativelayout