android(11)(ScrollView的简单用法)

来源:互联网 发布:锐智餐饮软件 编辑:程序博客网 时间:2024/05/03 22:31
布局文件:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:onClick="onClick"        android:text="添加" />    <ScrollView        android:layout_width="fill_parent"        android:layout_height="fill_parent" >        <LinearLayout            android:id="@+id/ll"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:orientation="vertical" >        </LinearLayout>    </ScrollView></LinearLayout>业务逻辑的实现:public class MainActivity extends Activity {    private LinearLayout llGroup;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        llGroup = (LinearLayout) findViewById(R.id.ll);    }    public void onClick(View view) {        // 添加一个TextView向llGroup        // 定义一个textview对象        TextView tv = new TextView(this);        tv.setText("张三   女   34");        // 把textview对象添加到linearlayout中        llGroup.addView(tv);    }
0 0
原创粉丝点击