ScrollView Tutorial (Android UI)

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>

As you can see the result is a scroll bar that we can use to see all the controls within the layout like this:

ScrollViewScrollView


Remember, the ScrollView can have only one child control, so we can make a container (Linear, relative, Table Layouts) the child of the ScrollView and put all the controls inside this child.




1 Comment:

Xandra Velasquez said...

When there is lengthy information we need scrolling with shape in web page.that's excellent you display this with example so it can be quickly comprehend.

Post a Comment

Recent Posts

Site Stats

Our Apps

Get it on Google Play

©2012-2014 Android Aspect - All rights reserved | Powered by Blogger

Creative Commons License