ScrollView布局或其RelativeLayout父级可能无用

时间:2014-01-27 23:51:28

标签: android

我正在开发Android 4及更高版本的应用程序。 一层生成此警告:此ScrollView布局或其RelativeLayout父级可能无用;将background属性传输到另一个视图

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

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp" >

        <WebView
            android:id="@+id/about"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"         
            android:layerType="software" />
    </ScrollView>

</RelativeLayout>

如何解决此警告?

3 个答案:

答案 0 :(得分:22)

此错误意味着RelativeLayout无用,因为它只包含一个View(ScrollView)。您应该将ScrollView作为父级,记住将xmlns:android标记移动到ScrollView以及#000背景属性。这将提高性能,并应删除错误。还要记住,ScrollView应该只有一个子视图。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:layout_marginBottom="3dp" >

    <WebView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"         
        android:layerType="software" />
</ScrollView>

答案 1 :(得分:7)

通常,您需要外部的ScrollView,它允许您滚动您拥有的内容。

我认为这就是你想要的:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="3dp" >

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#000"
        android:orientation="vertical" >

    <WebView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"         
        android:layerType="software" />

    </RelativeLayout>
</ScrollView>

答案 2 :(得分:0)

如果你真的想使用相对或线性布局,你可以使用线性布局后提供的Scrollview,你必须使用任何控件(Imageview,Imagebutton等..)然后它不会抛出任何警告/错误。

快乐编码

相关问题