我如何居中这为android
问题描述:
我想水平居中两个文本视图,以便在屏幕的顶部彼此相邻。我这样做是因为其中一个TextView会比另一个大。这里是我的代码我如何居中这为android
<TableRow
android:layout_gravity="center">
<TextView
android:layout_column="1"
android:padding="3dip"
android:gravity="right"
android:text="open" />
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Ctrl O" />
</TableRow>
答
我不知道你这个问题有点这就是你正在寻找:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="3dip"
android:text="open" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="3dip"
android:text="Ctrl O" />
</TableRow>
</TableLayout>
答
所以,你要彼此相邻和的中心的意见这样的屏幕?
| View1|reallylongView2 |
通常尽量避免表行,除非您真的想拥有一个表。如果你想要我上面展示的内容,最好的办法是有一个文本视图,特别是如果你的应用程序国际化,文本的顺序可能需要改变。
否则尝试相对布局父母,与居中水平线性布局的孩子,又包含两个文本的意见,像这样:
<RelativeLayout
...
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<TextView ... />
<TextView ... />
</LinearLayout>
</RelativeLayout>
否则,你需要澄清你在找什么。截图或ascii艺术将会有所帮助。
对不起,我不清楚。我的意思是在屏幕的第一行水平放置两个文本。 – Aaron 2011-12-27 01:55:02
如果您添加一个TableLayout ...请参阅编辑 – RonzyFonzy 2011-12-27 09:21:32