【问题标题】:Eclipse complains about uselessness of elements in layout xmlEclipse 抱怨布局 xml 中的元素无用
【发布时间】: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


    【解决方案1】:

    我认为这是因为在表格布局中使用表格行元素作为父级。

    您可以从 xml 中删除元素,因为已将行添加到表格布局中。

    在这里用作 is Useless 的父级,因此 Eclipse 会向您显示一个无用父级的警告

    【讨论】:

    • 你说得对,我可以省略 TableRows。不知道这行得通。
    • 你能写出两三句话吗?没完没了的单词真的很难理解。
    • 你到底有什么不明白的?我只是省略了 TableRows,所以我删除了所有 行,这似乎工作正常。
    【解决方案2】:

    我认为该表是无用的,因为简单的 LinearLayout 也应该完成这项工作。另请仔细阅读:possibly useless 不代表没用。

    【讨论】:

    • LinearLayout 不起作用,因为布局不再适合。如果它可能没用,那么它实际上不应该是一个警告。
    • 我不明白为什么这不再适合了...无论如何,很高兴知道您找到了解决方案。
    • 显然占位符按钮不知何故被忽略了,因此 ScrollView 没有像 TableLayout 那样按预期工作。我无法让它与 LinearLayout 一起使用。
    【解决方案3】:

    我认为当您只使用表格中的一行时会发生这种情况,而当我使用两行或更多行时,消息就会消失。 (为什么在一个表中只放一行,那么表本身已经是一行,这一定是背后的思想)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 2021-09-27
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2022-12-28
      相关资源
      最近更新 更多