标签:风飞雪未扬 从零开始学android scrollview组件的使用
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/mylayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> </ScrollView>JAVA文件设置
package com.example.scrollview; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout layout = new LinearLayout(this);//创建LinearLayout对象 layout = (LinearLayout) this.findViewById(R.id.mylayout);//实例化LinearLayout对象 //设置Button组件的宽和高 LinearLayout.LayoutParams Params = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); for (int i = 0; i < 20; i++) {//设置循环创建Button对系那个 Button button=new Button(this); button.setText("button"+i);//设置标题 button.setGravity(Gravity.CENTER);//设置对齐方式 layout.addView(button,Params);//添加组件 } } }
从零开始学android<ScrollView滚动视图.十八.>,布布扣,bubuko.com
从零开始学android<ScrollView滚动视图.十八.>
标签:风飞雪未扬 从零开始学android scrollview组件的使用
原文地址:http://blog.csdn.net/u013616976/article/details/38542555