2015-04-18 21 views
0

我使用this示例(表格佈局),在示例中它似乎工作正常,但在我的項目中我有一個額外的表格單元格。我使用VS 2013和Xamrin-Android(最新版本),我部署在API 21(android 5.0.1)上。問題是什麼?TableLayout當我在不同的行中使用不同的列

下面是對我

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:shrinkColumns="*" 
    android:stretchColumns="*" 
    android:background="#ffffff"> 

    <!-- Row 1 with single column --> 
    <TableRow 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:gravity="center_horizontal"> 
     <TextView 
      android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:textSize="18dp" android:text="Row 1" android:layout_span="3" 
      android:padding="18dip" android:background="#b0b0b0" 
      android:textColor="#000"/> 
    </TableRow> 

    <!-- Row 2 with 3 columns --> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 1" 
      android:layout_weight="1" android:background="#dcdcdc" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 2" 
      android:layout_weight="1" android:background="#d3d3d3" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 2 column 3" 
      android:layout_weight="1" android:background="#cac9c9" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
    </TableRow> 

    <!-- Row 3 with 2 columns --> 
    <TableRow 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:gravity="center_horizontal"> 
     <TextView 
      android:id="@+id/TextView04" android:text="Row 3 column 1" 
      android:layout_weight="1" android:background="#b0b0b0" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 

     <TextView 
      android:id="@+id/TextView04" android:text="Row 3 column 2" 
      android:layout_weight="1" android:background="#a09f9f" 
      android:textColor="#000000" 
      android:padding="20dip" android:gravity="center"/> 
    </TableRow> 

</TableLayout> 

,結果不會工作在我 result

+0

這個工作對我來說很好,但你可以試試這個說法,也許能解決你的問題: 以下添加到您的第三個錶行 機器人:layout_weight =「2」 – Mahmoud

+0

我測試你的XML,它爲我工作得很好。順便說一句,不要使用相同的ID爲所有的TextViews – Rami

+0

@Rami你在哪裏測試?在手機或視覺工作室或Android工作室?我知道ids這是虛擬項目:) –

回答

0

問題是在Visual Studio設計預覽沒有工作屬性的代碼。當我在真實的設備上測試它時,它工作。感謝@Rami對我提出的評論。

相關問題