2013-03-22 57 views
1

我編寫了下列xml代碼來安排表格格式的按鈕,但在模擬器或我的手機設備中運行時,它並不與我一起工作,其中按鈕顯示爲一個接一個(垂直),最後一個按鈕根本沒有顯示。Android:在橫向模式下使用TableLayout存在問題

的代碼是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/background" 
android:orientation="horizontal" 
android:padding="15dip" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:paddingLeft="20dip" 
android:paddingRight="20dip" 
    android:orientation="vertical" > 
<TextView 
    android:text="@string/main_title" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginBottom="20dip" 
    android:textSize="24.5sp"/> 
<TableLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:stretchColumns="*"> 
<TableRow > 
<Button 
    android:id="@+id/continue_button" 
    android:text="@string/continue_label" /> 
<Button 
    android:id="@+id/game_button" 
    android:text="@string/new_game_label" /> 
</TableRow> 
<TableRow> 
    <Button 
    android:id="@+id/about_button" 
    android:text="@string/about_label" /> 
    <Button 
    android:id="@+id/exit_button" 
    android:text="@string/exit_label"  /> 
    </TableRow> 
    </TableLayout> 
</LinearLayout> 

</LinearLayout> 

回答

0

此創建表格的佈局,請確認你的這個

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

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

     <TableRow 
      android:id="@+id/tableRow5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

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

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

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

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

     </TableRow> 

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

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

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

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

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

     </TableRow> 


    </TableLayout> 

</LinearLayout> 

嘗試這樣做的,爲澄清

的例子