Wednesday, February 20, 2013

Android ScrollView Tutorial

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

ScrollView gives us a scrollable layout for large data. Please consider the following XML layout to understand ScrollView: 



<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 1"
    />
    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 2"
    />
    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 3"
    />
    <EditText
    android:layout_width="fill_parent"
    android:layout_height="250dp"    
    />
    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 4"
    />
    <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 5"
    />
     <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 6"
    />
      <Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button 7"
    />
</LinearLayout>
</ScrollView>

No comments:

Post a Comment