2010-07-22 120 views
1

我花了这么多时间试图弄清楚这一点。我正在构建一个对话框布局,并试图让标题中心相对于对话框,同时在标题的两侧都有2个按钮。这些按钮应该朝向最左侧和最右侧'重力'。在Android布局中绝对居中

简单的部分是将对话框居中,或者执行最左边和最右边的按钮。这让他们在同一条线上打得很好。

简单的方法来想一想:

  1. 标题在对话框
  2. 2按键围绕着如何独立左对齐,右在同一行

有什么想法做这个?

回答

0

IMO我会尝试做一个自定义的对话框,并使用TableLayout来放置您的元素。 通过这种方式,您可以放置​​按钮,并使用标题上的属性stretchcolumn来按下屏幕侧面的按钮。 (如果我理解你很好)
alt text http://img801.imageshack.us/img801/4372/tablelayout.png
如果这个XML例子去,它应该工作,并从屏幕尺寸/旋转独立的:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:stretchColumns="1"> 

<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <Button android:text="Button01" android:id="@+id/Button01" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <TextView android:text="This is your title" android:id="@+id/TextView01" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" ></TextView> 
    <Button android:text="Button02" android:id="@+id/Button02" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</TableRow> 
</TableLayout> 
+0

感谢Sephy快速回复。如果我能保证屏幕尺寸,这将工作吗?就像,我不知道在未知分辨率下左右按钮有多远,或者是否存在一个我不完全明白的属性,但它允许这样做。谢谢。 – nitsujri 2010-07-23 01:55:17

+0

不要以为你需要知道屏幕的大小......我会为你做一些测试并编辑我的帖子。 – Sephy 2010-07-23 08:19:59