ScrollView in Android

We have seen FrameLayout in our last tutorial. Now we learn about other useful component ScrollView.

Assume that you have to make your profile screen and there is a lots of details. So some of the contents are dynamic and can grow beyond your screen size which is not visible to user. At that time we need a layout which is hold the all views when views size goes beyond layout and its possible to use with ScrollView.

ScrollView is the layout which is manage UI when holding views are larger than actual screen size. ScrollView enable vertical scrolling when views goes beyond layout size and show vertical scrollbar.

Remember this things in ScrollView

  • ScrollView have only one child view. Its mean that if you want to add more view inside scrollview than you have to use our standard layouts like LinearLayout, RelativeLayout or FrameLayout as a child view and add other views inside them.
  •  ScrollView mostly used when scrolling required for normal list data. Its not good way to manage large list data in scrollview. In this scenario use standard Android View like ListView, GridView or RecycleView instead of ScrollView.
  • Never use ListView or GridView inside Scrollview because they both have their own scrolling property.
  • ScrollView support vertical scrolling only. To use horizontal scrolling you can use  HorizontalScrollView.

android-scrollview-sample-skynils

Lets see code activity_main.xml

and our MainActivity.java file

and Now our output look like below.

android-scrollview-example-output-skynils

Download Project.
downlod

Now see next tutorial Toast in Android.