0

I have a RelativeLayout inside ScrollView. But ScrollView not scrolling when it as parent layout.

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:fillViewport="true" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/iv_about_background" android:layout_width="match_parent" android:layout_height="150dp" android:src="@drawable/stack" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/iv_about_background" android:paddingLeft="10dp" android:paddingRight="10dp" /> </RelativeLayout> </ScrollView> 

Edit: I removed rootView.setOnTouchListener from my fragment and ScrollView is working fine

9
  • where is your scrollview end? Commented Sep 23, 2017 at 5:46
  • 1
    stackoverflow.com/questions/20896963/… Commented Sep 23, 2017 at 5:47
  • @ Harshit Trivedi Missed that line when copied. question updated Commented Sep 23, 2017 at 5:48
  • 1
    @IntelliJ Amiya I know it will work if ScrollView will put inside a RelativeLayout. But is there any alternate solution. Commented Sep 23, 2017 at 5:50
  • set height to match parent.! Commented Sep 23, 2017 at 5:52

4 Answers 4

2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:fillViewport="true" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/iv_about_background" android:layout_width="match_parent" android:layout_height="350dp" android:src="@drawable/stack" /> <TextView android:text="rgergijsojsoierjgoegorijtowjtojrtoihjorjthlbkmoijbrotoojgowijtogirtjhowortgjowjtgjwrtgjowrijgtoiwjt" android:textSize="50sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/iv_about_background" android:paddingLeft="10dp" android:paddingRight="10dp" /> </RelativeLayout> 

I have changed the height-size of the image to 350dp and set text-size to 50sp to know whether the code you have posted works or not. Your code is perfectly fine but either you have to add more views inside scrollview or increase the size of the image/font-size of textview (shown in the code above).

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

Comments

1

There are several things that you can do:

  1. Make sure your content in relative layout height is more than the parent. I think 150dp and 10dp still below the parent height.

  2. Change width and height of ScrollView to fill_parent instead of match_parent, and do same things to the Relative Layout.

  3. Add android:scrollbars = "vertical" property in ScrollView

Hope it was helpful.

1 Comment

I tried with a large text on TextView, It is not scrolling
0

Try with

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:fillViewport="false" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_about_background" android:layout_width="match_parent" android:layout_height="150dp" android:src="@drawable/stack" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/iv_about_background" android:paddingLeft="10dp" android:paddingRight="10dp" /> </RelativeLayout> </LinearLayout> </ScrollView> 

8 Comments

@Ameer set RelativeLayout android:layout_height="match_parent"
My RelativeLayout height is match_parent. I tried ScrollView inside another layout. It works
@Ameer add Scrollview android:orientation="vertical" android:fillViewport="false"
Tried with android:fillViewport="false". But still not scrolling
I found the solution. I removed rootView.setOnTouchListener from my fragment
|
0

Try this hope it will help you.

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_about_background" android:layout_width="match_parent" android:layout_height="150dp" android:src="@drawable/stack" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/iv_about_background" android:paddingLeft="10dp" android:paddingRight="10dp" /> </RelativeLayout> </LinearLayout> 

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.