Reputation: 2769
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
Upvotes: 0
Views: 1367
Reputation: 1281
There are several things that you can do:
Make sure your content in relative layout height is more than the parent. I think 150dp and 10dp still below the parent height.
Change width and height of ScrollView to fill_parent
instead of match_parent
, and do same things to the Relative Layout.
Add android:scrollbars = "vertical"
property in ScrollView
Hope it was helpful.
Upvotes: 1
Reputation: 126
<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).
Upvotes: 2
Reputation: 971
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>
Upvotes: 0
Reputation: 75788
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>
Upvotes: 0