Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView layout or its RelativeLayout parent is possibly useless

Tags:

android

I'm developing an Android 4 and above application. One layer generate this Warning:This ScrollView layout or its RelativeLayout parent is possibly useless; transfer the background attribute to the other view

<?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>

How can I solve this warning?

like image 839
Hassan Bendouj Avatar asked Jan 27 '14 23:01

Hassan Bendouj


2 Answers

This error means that the RelativeLayout is useless, as it only contains one View (the ScrollView). You should make the ScrollView the parent, remembering to move the xmlns:android tag to the ScrollView, as well as the #000 background attribute. This will improve performance and should remove the error. Also remember that a ScrollView should only ever have one subview.

<?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>
like image 51
AngryPanther Avatar answered Nov 07 '22 01:11

AngryPanther


Usually, you'd want ScrollView on the outside, which allows you to scroll the content you have.

I think this is what you want:

<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>
like image 43
Kurty Avatar answered Nov 07 '22 02:11

Kurty