Android 为什么安卓lint会显示“;嵌套权重不利于性能”;当没有嵌套时?

Android 为什么安卓lint会显示“;嵌套权重不利于性能”;当没有嵌套时?,android,android-lint,Android,Android Lint,此布局中最后一个文本视图中的布局权重属性被lint突出显示为导致性能不佳。我怀疑lint警告的名称是错误的,因为没有嵌套的权重。有几个拉伸视图,我怀疑它的意思是依赖加权视图 构建此布局、避免此lint警告并提高性能的解决方案是什么 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" and

此布局中最后一个文本视图中的布局权重属性被lint突出显示为导致性能不佳。我怀疑lint警告的名称是错误的,因为没有嵌套的权重。有几个拉伸视图,我怀疑它的意思是依赖加权视图

构建此布局、避免此lint警告并提高性能的解决方案是什么

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:gravity="center_horizontal"
          android:background="@drawable/background_gradient"
    >
<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image4"
        android:layout_margin="6dp"
        android:contentDescription="@string/PLACEHOLDER_TEXT"
        />
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
    <Button
            style="@style/dashboard_button"
            android:id="@+id/home_management"
            android:text="@string/ICON_MANAGEMENT"
            />
    <Button
            style="@style/dashboard_button"
            android:id="@+id/home_calculators"
            android:text="@string/ICON_CALCULATORS"
            />
</LinearLayout>
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
    <Button
            style="@style/dashboard_button"
            android:id="@+id/home_guidelines"
            android:text="@string/ICON_GUIDELINES"
            />
    <Button
            style="@style/dashboard_button"
            android:id="@+id/home_faq"
            android:text="@string/ICON_FAQ"
            />
</LinearLayout>
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
    <Button
            style="@style/dashboard_button"
            android:id="@+id/home_refs"
            android:text="@string/ICON_REFERENCES"
            />
    <Button
            style="@style/dashboard_button"
            android:text=""
            android:visibility="invisible"
            />
</LinearLayout>
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:layout_margin="6dp"
        >
    <TextView
            android:text="@string/HOMEPAGE_CONTENT"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            />
    <View
            android:layout_width="8dp"
            android:layout_height="1dp"
            />
    <ImageView
            android:id="@+id/home_logo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/image7"
            android:contentDescription="@string/PLACEHOLDER_TEXT"
            />
</LinearLayout>
<Button
        android:id="@+id/home_web_site"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/HOMEPAGE_FOOTER"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:textSize="12sp"
        android:background="@drawable/button_red"
        android:layout_margin="6dp"
        android:textColor="#FFFFFF"
        />
</LinearLayout>


您的
@string/HOMEPAGE\u CONTENT
区域中的
文本视图
图像视图
嵌套在其父
线性布局
中,并指定了权重。我怀疑这是您的问题,尤其是因为父元素是
包装内容
,所以理论上不应该有任何空间供子元素延伸。

但是,您不必担心这一点,特别是如果您确实需要权重,如果这是正确声明布局的唯一方法。

关于这部分代码


另请参见:如果在构建过程中允许警告,则很难知道哪些警告是“正常”的,哪些不是。我更喜欢零容忍方法(通过修复警告或关闭警告),如果警告显示,这意味着它需要修复。但几乎所有加权视图都嵌套在某个东西中吗?我对警告的理解是,它说一个加权视图在另一个加权视图中是不好的,但在我的场景中,没有加权视图嵌套在彼此之间。其中有四个,有些人将依赖其他人。我仍然倾向于认为警告文本是不正确的,应该说“依赖”而不是“嵌套”。@ollice是的,加权视图总是在某些内容的内部,但它并不总是有用的。如果父视图的高度为1000像素,但子视图仅占800像素,则权重将确定如何分配额外空间。我怀疑这里的警告是,父视图被设置为完全占用其子视图定义的空间量(
wrap\u content
),因此权重不仅没有用处,而且可能会在布局过程中触发不必要的昂贵的
view
测量。我远非专家,但在我看来这是合乎逻辑的。你很少能知道有多少像素可用。“这似乎不是这样的时刻。”阿尔比亚马基尔:嗯,是的。这是我的观点。不过,用一些硬数字更容易说明这个概念。
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal"

<Button
        style="@style/dashboard_button"
        android:id="@+id/home_management"
        android:text="@string/ICON_MANAGEMENT"
        />
<Button
        style="@style/dashboard_button"
        android:id="@+id/home_calculators"
        android:text="@string/ICON_CALCULATORS"
        />