1

I am new to android and I have created a simple block of code which has a scrollView and an image. I want this scrollview to scroll smoothly. What do I have to do for that ? I have gone through many materials over internet, but all of those use hard terminologies which I'm not able to understand. Can someone please help me ? Thanks.

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" > <ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimaryDark"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/top_string" android:textColor="@android:color/white" android:textSize="16dp" android:textScaleX="1.5" /> <ImageView android:id="@+id/img" android:layout_width="300dp" android:layout_height="150dp" android:src="@drawable/dg_truck_main" android:layout_gravity="center_horizontal" android:background="@android:color/holo_blue_light" android:layout_marginTop="10dp" android:layout_centerHorizontal="true" android:layout_below="@id/text_view" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/top_string2" android:textColor="@android:color/white" android:textSize="16dp" android:textScaleX="1.5" android:layout_marginTop="50dp" android:layout_below="@id/img" /> </RelativeLayout> </ScrollView> </RelativeLayout> 
1
  • Set android:fillViewPort="true" for it. But my advise to use NestedScrollView. Commented Oct 5, 2018 at 7:12

4 Answers 4

2

You have added ScrollView inside RelativeLayout, what I suggest is that you should place RelativeLayout inside ScrollView tag. Please go through below code,

<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimaryDark"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/top_string" android:textColor="@android:color/white" android:textSize="16dp" android:textScaleX="1.5" /> <ImageView android:id="@+id/img" android:layout_width="300dp" android:layout_height="150dp" android:src="@drawable/dg_truck_main" android:layout_gravity="center_horizontal" android:background="@android:color/holo_blue_light" android:layout_marginTop="10dp" android:layout_centerHorizontal="true" android:layout_below="@id/text_view" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/top_string2" android:textColor="@android:color/white" android:textSize="16dp" android:textScaleX="1.5" android:layout_marginTop="50dp" android:layout_below="@id/img" /> </RelativeLayout> </RelativeLayout> </ScrollView> 
Sign up to request clarification or add additional context in comments.

5 Comments

okay Pranay I changed my code to what you suggested, what's next ?
@constant_learner Please run this project on the device and try to scroll on this screen.
Thanks for the help Pranay.
@constant_learner an upvote to this would be help me contribute more.
Oh... Awkward :)
1

I had a hard time resolving this issue. Finally found a solution very simple and very smooth outcome. In your recycler view set nested scrolling to false. Two ways to achieve it.

  1. Through xml file -

    android:nestedScrollingEnabled="false"

  2. Through java code -

    recyclerView.isNestedScrollingEnabled = false

1 Comment

this answer is the simplest and best way to make smoothing more responsive and smoother!
0

Okay I got my answer. Since I was new to android, I thought that "smooth scroll" is something else and we have to integrate it into our project. But a scrollView already gives smooth scrolling and so we do not need to write any extra code for that.

1 Comment

To improve your own answer, post the result of the scroll view with the smoothScroll function being called
0

//to make the scrollview faster //add the below line in xml

 android:fillViewport="true" 

//also add the following line to your java class // to make the scroll view faster

 scrollView.fullScroll(View.FOCUS_DOWN); scrollView.setSmoothScrollingEnabled(true); 

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.