Sunday 19 April 2015

How to use ScrollView in Android ?

Scrollview 

* 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.

* 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 for showing a list of related information and is optimized for dealing with large lists.

The following main.xml content shows a ScrollView containing a LinearLayout, which in turn contains some Button and EditText views:

<?xml​ version=”1.0”​encoding=”utf-8”?>

<ScrollView ​​​​
android:layout_width=”fill_parent”
​android:layout_height=”fill_parent” ​
​​​xmlns:android=”http://schemas.android.com/apk/res/android” ​​​​>

​​​​<LinearLayout
​​​​​​​​android:layout_width=”fill_parent”
​​​​​​​​android:layout_height=”wrap_content” ​​
​​​​​​android:orientation=”vertical” ​​​​​​​​>

​​​​​​​​<Button
​​​​​​​​​​​​android:id=”@+id/button1” ​
​​​​​​​​​​​android:layout_width=”fill_parent” ​​
​​​​​​​​​​android:layout_height=”wrap_content” ​
​​​​​​​​​​​android:text=”Button​1” ​​​​​​​​​​​​/>

​​​​​​​​<Button ​​​​​​​​​​​​
android:id=”@+id/button2” ​​
​​​​​​​​​​android:layout_width=”fill_parent” ​​
​​​​​​​​​​android:layout_height=”wrap_content” ​​
​​​​​​​​​​android:text=”Button​2” ​​​​​​​​​​​​/> ​​​​​​​​<Button ​​​​​​​​​​​​android:id=”@+id/button3” ​​​​​​​​​​​​android:layout_width=”fill_parent” ​​​​​​​​​​​​android:layout_height=”wrap_content” ​​​​​​​​​​​​android:text=”Button​3” ​​​​​​​​​​​​/> ​​​​​​​​<EditText ​​​​​​​​​​​​android:id=”@+id/txt” ​​​​​​​​​​​​android:layout_width=”fill_parent” ​​​​​​​​​​​​android:layout_height=”300px” ​​​​​​​​​​​​/> ​​​​​​​​<Button ​​​​​​​​​​​​android:id=”@+id/button4” ​​​​​​​​​​​​android:layout_width=”fill_parent” ​​​​​​​​​​​​android:layout_height=”wrap_content” ​​​​​​​​​​​​android:text=”Button​4” ​​​​​​​​​​​​/> ​​​​​​​​<Button ​​​​​​​​​​​​android:id=”@+id/button5” ​​​​​​​​​​​​android:layout_width=”fill_parent” ​​​​​​​​​​​​android:layout_height=”wrap_content” ​​​​​​​​​​​​android:text=”Button​5” ​​​​​​​​​​​​/> ​​​​</LinearLayout> </ScrollView>
Figure 3-12 shows the ScrollView enabling the users to drag the screen upward to reveal the views located at the bottom of the screen.

No comments:

Post a Comment