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

Has*_*ouj 10 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>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个警告?

Ang*_*her 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>
Run Code Online (Sandbox Code Playgroud)


Kur*_*rty 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>
Run Code Online (Sandbox Code Playgroud)