布局可能无用 - 不,它不是

时间:2014-05-12 06:40:16

标签: android android-layout layout warnings

我是Android开发的新手,并创建了一个如下所示的布局:

RelativeLayout
   ScrollView
      LinearLayout
         TextView

编译器抱怨ScrollView可能无用"。正如[android layout creation issue中所讨论的,我可以通过将ScrollView放在层次结构的顶部,删除多余的RelativeLayout来消除警告。但是,我想保留RelativeLayout,因为我将在运行时添加更多内容。是否有可能告诉编译器我想保留这个特定的布局?基本上,我想摆脱警告,但我不想完全禁用这种警告。

编辑:虽然完整的代码与问题无关,但它来了:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainFragment" >

    <ScrollView
        android:id="@+id/main_scrollview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" >
        <LinearLayout
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/test_right" 
                android:textSize="@dimen/test_right_textsize"/>
        </LinearLayout>
    </ScrollView>

</RelativeLayout>
编辑:为了澄清:我想在运行时添加的东西是另一个ScrollView,它独立于布局中的ScrollView,即新的ScrollView应该悬停在其余的顶部,重叠它,因此RelativeLayout

1 个答案:

答案 0 :(得分:2)

您可以在

中停用警告
Windows -> Preferences -> android -> Lint -> UselessParent

将其严重性更改为忽略

编辑:您可以在布局的根目录下面插入代码

tools:ignore="UselessParent"