Eclipse 抱怨布局 xml 中的元素无用
我有一个滚动视图。滚动视图只能包含一个元素,因此我将 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 警告:“RadioGroup 布局或其 TableRow 父级可能无用”
。 他们怎么可能没用呢?首先,我需要单选组来访问选定的单选按钮:
int selectedRadioId = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadioButton = (RadioButton)findViewById(selectedRadioId);
并且需要 TableLayout,因为我在 ScrollView 中只能有一个元素。我选择 TableView 因为下面有占位符按钮。那么这有什么问题呢?
I have a scrollview. A scrollview can only contain one element so I put my RadioGroup and the button below (which acts as a placeholder) inside a 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>
Now Eclipse shows me an xml warning: "The RadioGroup layout or its TableRow parent is possibly useless"
.
How can they be useless? First of all, I need the radiogroup to access the selected radio button:
int selectedRadioId = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadioButton = (RadioButton)findViewById(selectedRadioId);
And the TableLayout is needed due to the fact, that I can only have one element inside the ScrollView. I chose a TableView because of the placeholder button below. So what's wrong with that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这是因为使用表行元素作为表布局中的父元素。
您可以从 xml 中删除元素,因为已将行添加到表布局中。
使用作为父级在这里是无用的,所以 eclipse 会向您显示一个无用父级的警告
I think it's because of using table row element as parent of in table layout.
you can just remove elelment from xml because has add the row to Table layout.
Using as a parent of is Useless here so eclipse show you a warning of an useless parent for
我认为该表是无用的,因为简单的 LinearLayout 也应该完成这项工作。另请仔细阅读:
可能无用
并不意味着它没有用。I would think that the table is useless as a simple LinearLayout should do the job, too. Also read carefully:
possibly useless
doesn't mean it is useless.我认为当您仅使用表中的一行时,就会发生这种情况,当我使用两行或更多行时,消息就会消失。 (为什么在表中只放一行,那么表本身就已经是一行了,这一定是背后的想法)。
I think it occurs when you use only one row in a table, the moment I use two or more rows the message disappears. (Why put a only one row in a table, the table itself then is already one row must be the thought behind this).