O'Reilly logo

Learning Android by Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic TimelineActivity Layout

In this first iteration, we are creating a new layout for the TimelineActivity. This layout initially uses a TextView to display all the data that we have in the database. This is fine initially when we don’t have too many statuses to show.

Introducing ScrollView

Since it’s unlikely that all our data will fit on a single page, we need a way to scroll the text. To do that, we use ScrollView. ScrollView is like a window that uses scroll bars to display part of a larger component that takes more space than the screen provides. To make some potentially large views scrollable, you wrap them with this ScrollView. For example, we have a printout of friends’ statuses in the form of a TextView. As more statuses are added, this TextView could become large. In order to make it scrollable on a small screen, we put it into a ScrollView.

A ScrollView can contain only one direct child. If you want to combine multiple views into a single view that scrolls, you first need to organize those views into another layout, like you did previously in The StatusActivity Layout, and than add that layout into the ScrollView.

Typically you want ScrollView to take all the available space on the screen, so you will specify its layout width and height as fill_parent.

A ScrollView usually is not manipulated from Java, so it doesn’t require an id.

In Example 10-1, we wrap our TextView with a ScrollView so that when there’s a lot of text to display, ScrollView automatically adds scroll bars. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required