Android 困惑于;“无用的”;线头检查

Android 困惑于;“无用的”;线头检查,android,android-layout,android-lint,Android,Android Layout,Android Lint,我有一些布局文件,Lint对其发出以下警告: 无用的 摘要:检查是否可以删除父布局 优先级:2/10严重性:警告类别:性能 包含没有同级的子级的布局,不是滚动视图或 根布局,并且没有背景,可以删除并具有 它的孩子们直接搬进了父母家,以获得更高的回报 高效的布局层次结构 我感到困惑的部分是粗体的。我的布局(修复此警告之前)如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http:/

我有一些布局文件,Lint对其发出以下警告:

无用的

摘要:检查是否可以删除父布局

优先级:2/10严重性:警告类别:性能

包含没有同级的子级的布局,不是滚动视图或 根布局,并且没有背景,可以删除并具有 它的孩子们直接搬进了父母家,以获得更高的回报 高效的布局层次结构

我感到困惑的部分是粗体的。我的布局(修复此警告之前)如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/default_margin"
        android:paddingTop="@dimen/default_margin_small"
        android:paddingBottom="@dimen/default_margin_small">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingRight="@dimen/default_margin"
            android:orientation="vertical">

            <!-- TEXTVIEWS & EDITTEXTS HERE -->

        </LinearLayout>

    </ScrollView>

</LinearLayout>

但我修正了这样的警告:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/default_margin"
    android:paddingTop="@dimen/default_margin_small"
    android:paddingBottom="@dimen/default_margin_small">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingRight="@dimen/default_margin"
        android:orientation="vertical">

        <!-- TEXTVIEWS & EDITTEXTS HERE -->

    </LinearLayout>

</ScrollView>


这对我来说是有意义的,但是上面Lint检查中的粗体部分让我有点困惑,因为我在LinearLayout中有一个滚动视图。我是否应该这样修复它,或者将ScrollView作为布局文件的根元素没有问题,因为ScrollView继承自FrameLayout?

ScrollView
作为布局文件的根元素没有问题。lint的抱怨大概是关于您原来的root
LinearLayout
,它没有在孩提时代为
ScrollView
添加任何价值。

我也这么认为,但“不是ScrollView”让我感到困惑。整个句子有点让人困惑(至少对我来说,英语不是我的第一语言),我还以为它是在谈论
线性布局中的
滚动视图
。很高兴我能澄清这一点。谢谢。@RicardoAmaral:“我也这么认为,但“不是滚动视图”让我困惑。”——这是一条普通的信息。好吧,它们不是基于特定的视图层次结构模板化的。是的,但它似乎给出了一些可能的例子,其中一个恰好适合我的情况。我想我错了:)