Eclipse complains about uselessness of elements in

2019-03-06 09:34发布

问题:

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?

回答1:

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



回答2:

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.



回答3:

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).