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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章