android控件之ScrollView

android ScrollView即爲卷軸列表控件

關鍵代碼如下:

配置文件XML代碼:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
	android:id="@+id/myscroll" 
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<LinearLayout 
	    android:id="@+id/mylinear"
		xmlns:android="http://schemas.android.com/apk/res/android"
		android:orientation="vertical" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent">
	</LinearLayout>
</ScrollView>

activity關鍵代碼:

	private String data[] = { "上海中銳", "中銳控股", "中銳教育",
			"華芳教具", "元策", "江蘇騰銳信息技術",
			"江蘇分公司", "如皋基地", "唐山基地",
			"敏捷科技","中銳國際教育","華汽教育" }; // 定義數組,存儲顯示信息

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.main); // 調用默認的佈局管理器
		LinearLayout layout = (LinearLayout)findViewById(R.id.mylinear); // 取得組件
		for (int i = 0; i < this.data.length; i++) { // 通過循環方式將以上的信息通過Button組件進行封裝
			Button but = new Button(this);
			but.setText(this.data[i]); // 設置顯示文字
			layout.addView(but);
		}
	}

界面效果:


發佈了59 篇原創文章 · 獲贊 5 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章