2012-01-02 41 views
0

我有一個滾動視圖。 scrollview只能包含一個元素,所以我把我的RadioGroup和下面的按鈕(它充當佔位符)放在TableLayout中。Eclipse抱怨佈局xml中的元素無用

<ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal" > 

      <TableLayout 
       android:layout_width="300sp" 
       android:layout_height="wrap_content" > 

       <TableRow> 
        <RadioGroup 
         android:id="@+id/radioStateChoice" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" > 

         <RadioButton 
          android:id="@+id/radioW" 
          style="@style/CheckboxRadioStyle" 
          android:checked="true" 
          android:text="@string/wien" /> 

         <RadioButton 
          android:id="@+id/radioNoe" 
          style="@style/CheckboxRadioStyle" 
          android:text="@string/noe" /> 

         <RadioButton 
          android:id="@+id/radioOoe" 
          style="@style/CheckboxRadioStyle" 
          android:text="@string/ooe" /> 

         <!-- there are usually more radio buttons --> 
         <!-- I have shortened it to keep the example smaller --> 
        </RadioGroup> 
       </TableRow> 

       <TableRow> 
        <Button 
         android:layout_width="60sp" 
         android:layout_height="50sp" 
         android:visibility="invisible" /> 
       </TableRow> 
      </TableLayout> 
     </ScrollView> 

現在Eclipse中顯示我的XML警告:"The RadioGroup layout or its TableRow parent is possibly useless"。 他們怎麼會無用?首先,我需要的RadioGroup中訪問選定的單選按鈕:

 int selectedRadioId = radioGroup.getCheckedRadioButtonId(); 
     RadioButton selectedRadioButton = (RadioButton)findViewById(selectedRadioId); 

而且TableLayout需要由於這樣的事實,那我只能有滾動型中的一個元素。由於下面的佔位符按鈕,我選擇了一個TableView。那有什麼問題呢?

回答

1

我認爲這是因爲在表格佈局中使用表格行元素作爲父元素。

您可以從xml中刪除elelment,因爲已將行添加到Table佈局。

使用作爲父母是無用這裏,所以日食告訴你一個沒用的父母爲

+0

你說得對,我可以省略TableRows。不知道這是有效的。 – Bevor 2012-01-02 09:44:01

+2

你能說出兩三句話嗎?真的很難理解永無止境的文字。 – WarrenFaith 2012-01-02 09:47:55

+0

你到底明白了什麼?我只是省略了TableRows,所以我刪除了所有的這幾行,這似乎正常工作。 – Bevor 2012-01-02 10:01:00

0

我認爲該表無用,因爲簡單的LinearLayout也應該完成這項工作。仔細閱讀:possibly useless並不意味着它是無用的。

+0

LinearLayout不起作用,因爲佈局不再適合了。如果它可能無用,那麼它實際上不應該是一個警告。 – Bevor 2012-01-02 09:27:25

+0

我不明白爲什麼這不應該適應了......無論如何,很高興知道你已經找到了解決方案。 – WarrenFaith 2012-01-02 09:48:45

+0

很明顯,佔位符按鈕被忽略了,所以ScrollView沒有像TableLayout那樣按預期工作。我無法使用LinearLayout工作。 – Bevor 2012-01-02 09:57:54

0

警告我認爲當你在一個表中只使用一個排它發生,我用兩個或兩個以上行的那一刻消息消失。 (爲什麼只把一行放在表中,表本身就已經是一行,一定是這個背後的想法)。