控件:ScrollView --- 滚动视图
MyScrollViewDemo.java
View Code
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
public class MyScrollViewDemo extends Activity {
// 准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中
private String data[] = { "AAAAAAAAAA", "BBBBBBBBB", "CCCCCCCCCCC",
"DDDDDDDDDD", "EEEEEEEEEE", "FFFFFFFFFF",
"GGGGGGGGGG", "HHHHHHHHHH", "IIIIIIIIIIII",
"JJJJJJJJJJJJJJJJJ" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 调用默认的布局管理器
super.setContentView(R.layout.main);
// 取得组件
LinearLayout layout = (LinearLayout) super.findViewById(R.id.mylinear);
// 定义布局参数
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
// 通过循环方式将以上的信息通过Button组件进行封装
for (int x = 0; x < this.data.length; x++) {
Button but = new Button(this);
// 设置显示文字
but.setText(this.data[x]);
// 增加组件
layout.addView(but, param);
}
}
}