private LinearLayout.LayoutParams LP_FF = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); ScrollView sv = new ScrollView(this); sv.setLayoutParams( LP_FF ); LinearLayout layout = new LinearLayout(this); //线性布局方式 layout.setOrientation( LinearLayout.VERTICAL ); //控件对其方式为垂直排列 sv.addView( layout ); //把线性布局加入到ScrollView中 setContentView(sv); //设置当前的页面为ScrollView CheckBox tv = new CheckBox(this); tv.setId(10); tv.setText( "fsdfsdfsdfsd" ); layout.addView( tv );
连通LinearLayout和CheckBox一起打包动态创建。使用getLayoutInflater().inflate(...)方法获得LinearLayout对象实例。