Home Tutorials Hints & Tips

Getting Started in Android Development

Part 14 - The ScrollView

As the name implies, the ScrollView allows the screen to be scrolled should the contents of the screen need more than the height or width to be displayed. Without a ScollView the screen would simply truncate the contents without the ability to scroll.

Adding a ScrollView to a layout is straightforward. A ScrollView can only have one child view. This is typically a linear or relative layout. The ScrollView must have the XML name space moved from the child layout to the ScrollView itself or XML errors will be present prior to the name space. The only other consideration is to whether the orientation is set to vertical or horizontal. Our example is shown below. Originally, the Linear Layout was the parent with ten TextViews as child views. The ScrollView was then added as below.

A new activity was set up and the toast in the ListviewActivity file replaced with a new Intent and StartActivity method. After this tutorial your ListviewActivity.java file should look similar to the one below. Don’t forget to update the Android Manifest file to include the new Activity.

The Android Manifest File:

The new ScrollViewActivity.java file:

Download Download tutorial set 1

Privacy and Cookies Disclaimer Copyright
© 2015 - 2018 North Border Tech Training All rights reserved