Thursday 17 March 2016

How to Make Your App Scrollable?

Are you new to android programming and wondering how to make your app scrollable? Well, it’s pretty simple. Here is how to do it.


<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">


<LinearLayout
   <TextView ....... />
   <CheckBox ....... />


</LinearLayout>
</ScrollView>

As you can see from the above example, to make your app scrollable you have to put all the contents of your app into the ScrollView. ScrollView is a FrameLayout. ScrollView accepts only one child view. This might sound a little confusing. No, it does not mean you can’t have the rest of your views. From the above example, you can see that the ScrollView is parent to the Linear Layout but not to TextView and CheckBox. The LinearLayout is parent to our TextView and CheckBox.  Simple, isn’t it?

FillViewport is an attribute that defines whether the ScrollView should stretch its contents to fill the entire screen or not. If the child is bigger than the ScrollView then it does not make a difference. P.S this attribute works with Relative Layout only.




















No comments:

Post a Comment