Выравнивание элементов диалога - PullRequest
0 голосов
/ 17 марта 2012

У меня есть следующий макет, изложенный в XML, который устанавливается как представление содержимого диалогового окна, и я пытаюсь сделать так, чтобы две кнопки были расположены по центру, чтобы они отображались в центре строки таблицы, в которой они находятся, ночто бы я с ними ни делал, они остаются слева.Это как-то связано с тем, что внутри диалога?Как я могу это исправить?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="10dip"
   android:background="#FF9E00"
   android:orientation="vertical">

   <TableLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content">

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#A0DB84">
   <TextView android:id="@+id/creatediagtxt"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="TEST"/>
   </TableRow>

   <TableRow
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="#004884"> 

 <Button android:id="@+id/Button01" 
 android:layout_width="wrap_content" android:layout_height="wrap_content" 
 android:text="Cancel" android:layout_gravity="center"/>

 <Button android:id="@+id/Button02" 
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:text="Done" />

 </TableRow>

 </TableLayout>

1 Ответ

2 голосов
/ 17 марта 2012

Вы можете поиграть с layout_weight. Например:

<TableRow
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:background="#004884"
   android:layout_weight="1"> 

 <Button android:id="@+id/Button01" 
  android:layout_width="wrap_content" android:layout_height="wrap_content" 
   android:text="Cancel" android:layout_weight="0.5"/>

 <Button android:id="@+id/Button02" 
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:text="Done" android:layout_weight="0.5" />

 </TableRow>
...