The tutorial will show you, how to use Android ScrollView component and create a simple example using various ScrollView properties.
ScrollView is a special kind of layout, designed to hold view larger than its actual size. When the Views size goes beyond the ScrollView size, it automatically adds scroll bars and can be scrolled vertically.
- ScrollView can hold only one direct child. This means that, if you have complex layout with more view controls, you must enclose them inside another standard layout likeLinearLayout, TableLayout or RelativeLayout.
- You can specify
layout_widthto adjust height and width of screen.
- Scrollview is ideal for screens where scrolling is required, but it is an overhead when scroll view is used to render a larger list of data. Android provides specialized adapter views likeListView, GridView and Recycler View (Introduced in Android Lollipop) are recommended for long lists.
- You should never use a ScrollView with a ListView or GridView, because they both takes care of their own vertical scrolling.
- ScrollView only supports vertical scrolling. Use
HorizontalScrollViewfor horizontal scrolling.
android:fillViewportproperty defines whether the scrollview should stretch its content to fill the viewport. You can set the same property by calling
You can download the project from github