Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对话框元素的对齐_Android_Centering_Android Tablelayout - Fatal编程技术网

Android 对话框元素的对齐

Android 对话框元素的对齐,android,centering,android-tablelayout,Android,Centering,Android Tablelayout,我用XML设置了以下布局,它被设置为对话框的内容视图 我要做的是将两个按钮居中,使它们显示在它们所在的表格行的中心,但无论我对它们做了什么,它们都保持在左侧。这与它在一个对话框中有关吗?我怎样才能修好它 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_par

我用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>


您可以使用
布局重量
。例如:

<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>