Aug 14, 2012

HorizontalScrollView And ScrollView

java.lang.Object
   ↳android.view.View
    ↳android.view.ViewGroup
     ↳android.widget.FrameLayout
      ↳android.widget.HorizontalScrollView

Class Overview


Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A HorizontalScrollView 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 horizontal orientation, presenting a horizontal array of top-level items that the user can scroll through.
The TextView class also takes care of its own scrolling, so does not require a HorizontalScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.
HorizontalScrollView only supports horizontal scrolling. For vertical scrolling, use either ScrollView orListView.

ScrollView and HorizontalScrollView are layout container for a view hierarchy that can be scrolled vertically or horizontally by the user, allowing it to be larger than the physical display. A ScrollView/HorizontalScrollView 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.

XML code :
------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="HorizontalScrollView And ScrollView  "
  />
<HorizontalScrollView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<LinearLayout
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="First HorizontalScrollView" />
<LinearLayout
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<Button
  android:text="Horizontal A1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal A2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal A3"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal A4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal A5"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<LinearLayout
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Second  HorizontalScrollView" />
<LinearLayout
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<Button
  android:text="Horizontal B1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal B2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal B3"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal B4"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal B5"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
<Button
  android:text="Horizontal B6"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >
<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView" />
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Button C"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView D"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView E"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView F"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView G"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView H"/>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Vertical ScrollView I"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

For Full Source Clik Here : ScrollView



1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete