此LinearLayout布局或其FrameLayout父级是无用的;将background属性传递给另一个视图

时间:2013-01-30 13:42:26

标签: android

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff000000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="80.0dip"
            android:orientation="vertical" >

            <HorizontalScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:paddingBottom="1.0dip"
                android:paddingTop="1.0dip"
                android:scrollbars="none" >

                <include layout="@layout/quickactions_buttons_part" />
            </HorizontalScrollView>
        </LinearLayout>

但我得到了这个警告

This LinearLayout layout or its FrameLayout parent is useless; transfer the background attribute to the other view

This HorizontalScrollView layout or its LinearLayout parent is useless

有没有人知道我该怎么做才能消除这条消息?

2 个答案:

答案 0 :(得分:5)

您有一个单独的组件(行)垂直线性布局,包含另一个线性布局。这没有任何意义,因为布局是多个组件的容器。如果只有一个组件,那么这个容器是多余的,可以直接用它所拥有的单个组件替换。

同样,第二个LinearLayout也没有意义,只有一个组件HorizontalScrollView。唯一可能有问题的是现在需要在组件上指定“80.0dip”属性。

因此,您的布局不必要复杂。 FrameLayout的内容可以更简单地重写为

<HorizontalScrollView
   android:layout_width="fill_parent"
   android:layout_height="80.0dip"
   android:paddingBottom="1.0dip"
   android:paddingTop="1.0dip"
   android:scrollbars="none" >
   <include layout="@layout/quickactions_buttons_part" />
</HorizontalScrollView>

导致代码运行得更快,更容易理解。

答案 1 :(得分:0)

我认为这是由于FrameLayout,1st LinearLayout和2nd LinearLayout在Horizo​​ntalScrollView中包含所有内容时无法解决任何问题。

相关问题