Vertical ScrollView

by / Monday, 05 August 2013 / Published in Android

ScrollView is a layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

Here is a code for vertical scrollview. It is used to display all content of an activity by scrolling vertically.

code :

code for layout:

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:textSize="60pt"
android:text="@string/hello_world" />
</ScrollView>

code for activity :

ScrollView sview=new ScrollView(this);//create scrollview dynamically
TextView txt=new TextView(this);//create a textview dynamically
sview.addView(txt);//add textview object to its parent (scrollview)

Tagged under: ,
TOP