Monday, May 21, 2012 : Article > Android User : Register | Login
บทความ
Webboard
วีดีโอ
บทความจากเพื่อนๆ Guru
06
ตัวอย่างการสร้าง ScrollView เพื่อเพิ่มพื้นที่การใช้งานหน้าจอบน Android 

1.สร้าง project ด้วยการเปิดโปรแกรม Eclipse แล้วไปที่ File > New > Other > Android > Android Project


2.จากนั้น เปิด res > layout  > main.xml 


คลิกที่ Tab main.xml ด้านล่างและใส่โค้ดดังนี้ได้เลยค่ะ

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
	android:orientation="vertical" android:layout_width="fill_parent" 
	android:layout_height="fill_parent" android:fillViewport="true"> 

<LinearLayout android:id="@+id/LinearLayout01" android:orientation="vertical" 
android:layout_width="fill_parent" android:layout_height="wrap_content"> 
	<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" 
		android:layout_height="wrap_content" android:text="This is a header" 
		android:textAppearance="?android:attr/textAppearanceLarge" 
		android:paddingLeft="8dip" android:paddingRight="8dip" android:paddingTop="8dip">
	</TextView>
	<TextView android:text="@+id/TextView02" android:id="@+id/TextView02" 
		android:layout_width="wrap_content" android:layout_height="fill_parent" 
		android:layout_weight="1.0">
	</TextView>

	<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" 
	android:layout_height="wrap_content"> 
		<Button android:id="@+id/Button01" android:layout_width="wrap_content" 
			android:layout_height="wrap_content" android:text="Submit" 
			android:layout_weight="1.0">
		</Button> 
		<Button android:id="@+id/Button02" android:layout_width="wrap_content" 
			android:layout_height="wrap_content" android:text="Cancel" 
			android:layout_weight="1.0">
		</Button> 
	</LinearLayout> 
</LinearLayout> 
</ScrollView>

ผลลัพธ์ที่ได้


3.เปิด ScrollView.java


และใส่โค้ดดังนี้

package th.co.bighead.exsample.ScrollView; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class ScrollView extends Activity { 
/** Called when the activity is first created. */
 @Override 
	public void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.main); 
		TextView view = (TextView) findViewById(R.id.TextView02); 
		String s=""; 
		for (int i=0; i < 100; i++) { 
		s += "mobileDevguru "; 
		} 
		view.setText(s); 
	} 
}

จากนั้นให้รันโปรแกรม

ผลการรันโปรแกรม
 


Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.
Home | Article | Webboard | Video | Blog | Showcase | News
Copyright 2010 by devguru.mobi