Recipe 2.14 Using the ScrollView

Android Versions
Level 1 and above
Permissions
None
Source Code to Download from Wrox.com
UsingScrollView.zip

A ScrollView is a special type of FrameLayout in that it enables users to scroll through a list of views that occupy more space than the physical display provides. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout. This recipe shows how to use the ScrollView.

Solution

Assume you have the following code snippet in the activity_main.xml file:

<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 3" /> <EditText android:id="@+id/txt" android:layout_width="match_parent" android:layout_height="600px" /> <Button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:id="@+id/button5" android:layout_width="match_parent" ...

Get Android Application Development Cookbook: 93 Recipes for Building Winning Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.