11

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?

1
  • if any of answers below answer your question, please mark them as answer.
    – AaA
    Aug 11, 2017 at 8:01

3 Answers 3

26

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

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

If you really want to use relative or Linear layout you can use ahead of Scrollview provided after linear Layout you will have to use any control(Imageview,Imagebutton etc..) then it will not throw any warning/error.

Happy coding

1
  • 1
    This should be comment
    – ketan
    Apr 1, 2016 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.