Reputation: 1641
I have tried making ScrollView parent of the TextView, but then I also have a background image set on this RelativeLayout, and it gives me an error saying:"This ScrollView Layout or its RelativeLayout parent is useless; transfer the background attribute to the other view". And if I make ScrollView the parent of my RelativeLayout, it stretches the background image, which I don't want. Here's my xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hp_instr" >
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/instr"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
</ScrollView>
</RelativeLayout>
Upvotes: 0
Views: 164
Reputation: 11978
ScrollView
needs only one child ViewGroup which will contain other child views. And as your hint said: "The parent RelativeLayout is useless" indeed, because now you can have only the ScrollView and set to it the background:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/hp_instr" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/instr"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
NOTE: A last thing to know, when you'll use a ScrollView, the child ViewGroup (LinearLayout, RelativeLayout, TableLayout, whatever) must to declare its height to wrap_content
because the height expands regarding its content (same for HorizontalScrollView
but for the width).
Upvotes: 2
Reputation: 138
You need to place your scrollview first (below xml-tag) with layout_width and height to fill_parent and your relativelayout can match_parent.
I hope this solution will help for you.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/hp_instr" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/instr"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</ScrollView>
Upvotes: 0
Reputation:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hp_instr" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/instr"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Upvotes: 1