【发布时间】:2012-01-02 08:56:06
【问题描述】:
我有一个滚动视图。滚动视图只能包含一个元素,因此我将 RadioGroup 和下面的按钮(用作占位符)放在 TableLayout 中。
<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 是因为我在 ScrollView 中只能有一个元素。由于下面的占位符按钮,我选择了 TableView。那有什么问题呢?
【问题讨论】:
标签: android xml android-layout scrollview android-tablelayout