Designing layouts – 3
We can use Linear and Relative Layouts for defining few set of views under it. When it comes to show many number of views inside the layout, the layout should have scrolling capability to show all the views. ScrollView is such type of layout that helps in defining such functionality. Unlike other layouts, ScrollView helps user to scroll across all the views present inside it.
Below code will show it as parent layout inside the XML file
ScrollView has a rule to be followed. “ScrollView should have only one child View/Layout.” Hence, ScrollView will have Linear/ RelativeLayout as the only child. You can declare all other views inside Linear/ RelativeLayout.
In android, TextView is the View that helps us in showing the text inside any layout. The xml code of the TextView will look as below:
Let us declare a LinearLayout inside our ScrollView. As we need a scroll functionality for our screen, let us declare some TextViews inside the LinearLayout.
The Complete Code :
So as the you can observe in the code, ScrollView will having only one direct child. Hence all other views which you need in the screen should be declared inside the direct child. The screen will get the scroll capability to traverse through all the views.
The Complete Preview :
These are number of ways to design ScrollView. ScrollView can also be placed inside any layout to manage the screen arrangement. As we see, the scroll now here is vertical, we can have horizontal scroll using HorizontalScrollView.
HorizontalScrollView helps in arranging elements horizontally and then gives them scroll capability. As specified for ScrollView, HorizontalScrollView should also have only one direct child.
Place one direct child LinearLayout inside the HorizontalScrollView. Also place TextViews repeatedly to check the scroll capability.
After acquiring the scroll capability horizontally, the screen looks like below:
Download this tutorial
291 total views, 1 views today