วันศุกร์ที่ 20 กรกฎาคม พ.ศ. 2555

Android Scrollview

-->

Android Scrollview

ScrollViewActivity.java Code

package android.example.scrollview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;


public class ScrollViewActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.scrollbar3);
       
        findViewById(R.id.view3).setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    }
}

scrollbar.xml Code

<?xml version="1.0" encoding="utf-8"?>

<!-- Demonstrates scrolling with a ScrollView. -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099CC"
    android:orientation="vertical">

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="ScrollView ( Vertical )"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:orientation="horizontal" >

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="120dip"
            android:layout_weight="1"
            android:layout_marginLeft="5dp"
            android:background="#FF0000" >

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_2_text" />
            </LinearLayout>
        </ScrollView>

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="120dip"
            android:layout_weight="1"
            android:layout_marginLeft="5dp"
            android:background="#00FF00"
            android:paddingRight="12dip" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#60AA60"
                android:text="@string/scrollbar_3_text"
                android:textColor="#000000" />

        </ScrollView>

        <ScrollView
            android:id="@+id/view3"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_height="120dip"
            android:layout_marginLeft="5dp"
            android:background="@android:drawable/edit_text" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="#000000"
                android:text="@string/scrollbar_3_text" />
        </ScrollView>
    </LinearLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="Horizontal ScrollView"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <HorizontalScrollView
            android:id="@+id/view4"
            android:layout_width="fill_parent"
            android:layout_height="120dip"
            android:scrollbarStyle="outsideOverlay"
            android:background="@android:drawable/edit_text">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/scrollbar_3_text"
                    android:textSize="30dp"
                    android:textColor="#0000FF" />

            </LinearLayout>

        </HorizontalScrollView>
       
        <HorizontalScrollView
            android:id="@+id/view5"
            android:layout_width="fill_parent"
            android:layout_height="120dip"
            android:scrollbarStyle="outsideInset"
            android:background="@android:drawable/edit_text">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent" >
               
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/about" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/exit" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/how" />
                 
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/set" />
                
                 <ImageView
                android:id="@+id/imageView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                  <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/about" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/exit" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/how" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/set" />
                
                
                 <ImageView
                android:id="@+id/imageView3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                  <ImageView                
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/about" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/exit" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/how" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                 
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/set" />
                
                
                 <ImageView
                android:id="@+id/imageView4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
                
                 <ImageView               
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/ic_launcher" />
               
            </LinearLayout>
          
           
        </HorizontalScrollView>
       
    </LinearLayout>
</LinearLayout>

string.xml Code

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, Activity!</string>
    <string name="app_name">ScrollView</string>
   
   
    <string name="scrollbar_1_text">Lorem ipsum dolor sit amet.</string>
    <string name="scrollbar_2_text">Lorem ipsum dolor sit amet.</string>
    <string name="scrollbar_3_text">
 The Android platform is a software stack for mobile devices including an
 operating system, middleware and key applications. Developers can create
 applications for the platform using the Android SDK. Applications are written
 using the Java programming language and run on Dalvik, a custom virtual
 machine designed for embedded use which runs on top of a Linux kernel.

 If you want to know how to develop applications for Android, you\'re in the
 right place. This site provides a variety of documentation that will help you
 learn about Android and develop mobile applications for the platform.

 An early look at the the Android SDK is also available. It includes sample
 projects with source code, development tools, an emulator, and of course all
 the libraries you\'ll need to build an Android application. What would it take
 to build a better mobile phone?
    </string>

</resources>



Download Android ScrollView Example Code




Android Control ควบคุมอุปกรณ์ต่างๆ ด้วย Android

สอนเขียน Android  สอนเขียนโปรแกรม Android