2012-11-29 51 views
0

我的主要活動Android .xml表格佈局是一個簡單的圖像表格,3列4行。一切都設置爲match_parent的寬度,高度和重量1,這在GUI編輯器中顯示稍微錯誤,但在我的手機上可以。爲什麼我不能在表格佈局中混合文本行與圖像行?

如果我然後在底部行之前的.xml中添加一行以添加文本標籤,它或者根本不呈現該行,或者在稍微戳一下之後呈現文本,但會切斷底部最後一行。

以下是.xml,長時間囉嗦,但非常簡單和重複。

<TableLayout 
    android:layout_gravity="bottom" 
    android:layout_weight="1" 
    android:stretchColumns="*"  
    android1:layout_width="match_parent" 
    android1:layout_height="match_parent" 
    android1:layout_alignParentBottom="true" 
    android1:layout_alignParentLeft="true" 
    android1:layout_alignParentRight="true" 
    android1:layout_alignParentTop="true" > 

    <TableRow 
     android1:id="@+id/tableRow1" 
     android1:layout_width="match_parent" 
     android1:layout_height="match_parent" 
     android1:layout_weight="1" > 

     <ImageView 
      android1:id="@+id/x2" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:clickable="true" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_2x" 
      android1:tag="2" /> 

     <ImageView 
      android1:id="@+id/x3" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_3x" 
      android1:tag="3" /> 

     <ImageView 
      android1:id="@+id/x4" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_4x" 
      android1:tag="4" /> 

    </TableRow> 

    <TableRow 
     android1:id="@+id/tableRow3" 
     android1:layout_width="match_parent" 
     android1:layout_height="match_parent" 
     android1:layout_weight="1" > 

     <ImageView 
      android1:id="@+id/x5" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_5x" 
      android1:tag="5" /> 

     <ImageView 
      android1:id="@+id/x6" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_6x" 
      android1:tag="6" /> 

     <ImageView 
      android1:id="@+id/x7" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_7x" 
      android1:tag="7" /> 

    </TableRow> 

    <TableRow 
     android1:id="@+id/tableRow4" 
     android1:layout_width="match_parent" 
     android1:layout_height="match_parent" 
     android1:layout_weight="1" > 

     <ImageView 
      android1:id="@+id/x8" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_8x" 
      android1:tag="8" /> 

     <ImageView 
      android1:id="@+id/x9" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_9x" 
      android1:tag="9" /> 

     <ImageView 
      android1:id="@+id/x10" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="SetTable" 
      android1:padding="5dp" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/menu_10x" 
      android1:tag="10" /> 

    </TableRow> 

    <TableRow 
     android1:id="@+id/TableRow01" 
     android1:layout_width="match_parent" 
     android1:layout_height="match_parent" 
     android1:layout_weight="1" > 

     <TextView 
      android1:id="@+id/TextView02" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_span="2" 
      android1:layout_weight="1" 
      android1:text="Left two buttons" 
      android1:textColor="#000000" 
      android1:textSize="16dp" 
      android1:textStyle="normal" /> 

     <TextView 
      android1:id="@+id/textView1" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:text="Right button" 
      android1:textColor="#000000" 
      android1:textSize="16dp" 
      android1:textStyle="normal" /> 

    </TableRow> 

    <TableRow 
     android1:id="@+id/TableRow5" 
     android1:layout_width="match_parent" 
     android1:layout_height="match_parent" 
     android1:layout_weight="1" > 

     <ImageView 
      android1:id="@+id/ImageView07" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="LaunchPR" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/pushbutton_1" 
      android1:tag="1" /> 

     <ImageView 
      android1:id="@+id/ImageView08" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="LaunchPR" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/pushbutton_1" 
      android1:tag="2" /> 

     <ImageView 
      android1:id="@+id/ImageView09" 
      android1:layout_width="match_parent" 
      android1:layout_height="match_parent" 
      android1:layout_weight="1" 
      android1:onClick="LaunchPR" 
      android1:scaleType="fitCenter" 
      android1:src="@drawable/pushbutton_2" 
      android1:tag="3" /> 

    </TableRow> 

</TableLayout> 

+0

你還可以發佈用於添加額外行的代碼嗎? – Luksprog

+0

對不起,我自言自語。它都在.xml中;我不會動態添加它。我的意思是我有表格處理圖像,然後用編輯器/ xml添加新行。 ;) –

+1

你知道你用於某些視圖的屬性嗎?我特別指的是你似乎在所有視圖中使用的'layout_weight'。 – Luksprog

回答

0

如果您設置的TableLayout填補父(match_parent)你不需要layout_weight屬性。您將需要使用layout_weight(在TableRows)如果你打算讓TableRows垂直佔據相等空間(例如,如果你有4行,那麼你會設置在TableLayoutandroid:layout_weight="1"android:weightSum="4"TableRows到做四個相同大小的垂直行(填滿屏幕))。

此外,android:stretchColumns="*"屬性將拉伸所有表格的列,因此您不需要TableRow的子項上的layout_weight。

+0

在大屏幕上嘗試我的界面,這似乎不是真的。我需要在我的主TableLayout和重量1的每一行的權重總和2,否則它只能畫到屏幕高度的一半。 –

+0

@TickledPink如果你有4行,那麼'weightSum'應該是4(並且行之間的權重相等)。我不明白爲什麼這會在更大的屏幕上失敗。 – Luksprog

+0

我有嵌套的表格。主容納桌有兩排將屏幕分成上半部分和下半部分,並且只在屏幕的上半部分安裝在大屏幕上,直到我添加了重量。 –

相關問題