Android ScrollView With Examples

Android ScrollView allows us to create a scrollable layout on the android screen.

Android ScrollView

ScrollView is a special type of FrameLayout that allows users to scroll through a list of views. It is useful when the layout occupies more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout.

Note: Do not use a ListView together with the ScrollView. The ListView is designed to display a list of related information and is optimized for dealing with large lists. Also, ListView contains built-in scrolling capabilities.

  1. ScrollView only supports vertical scrolling. We have to use HorizontalScrollView for horizontal scrolling.
  2. The android:fillViewport property defines whether the scrollview should stretch its content to fill the viewport.

ScrollView XML Layout

We have explicitly assigned a larger size of the layout_height of the TextView so that ScrollView comes into use.

Android ScrollView Example Project

android-layout-part-3-project

This project consists of two Activities: MainActivity and SecondActivity.

The MainActivity displays the TableLayout.

The SecondActivity.java contains the ScrollView with a LinearLayout inside it.

Output:

android-layout-table-output

In the above image, the individual columns in all the three rows are highlighted.

android ScrollView example output

The vertical scrollbars are visible on the right side of the screen.

Reference: ScrollView Official Doc

By admin

Leave a Reply

%d bloggers like this: