0

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> 

3 Answers 3

2

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).

Sign up to request clarification or add additional context in comments.

3 Comments

I also want the background image , and if I set it as an attribute in RelativeLayout or scrollview, it gets stretched. How should I make the textview scrollable and not the whole image?
Sorry , it was my mistake , I didn't save it and tried running it. It's ok now, just the way I wanted. Thank you very much.
@AmanGrover OK, I will do a rollback. Thank you. And good coding.
1
<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> 

Comments

0

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.