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?
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With