<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Add row"></Button> <ScrollView android:id="@+id/ScrollView01" android:layout_width="wrap_content" android:layout_height="wrap_content">   <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">     <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">      <TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="textfield 1-1"></TextView>       <CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>    </TableRow>   </TableLayout></ScrollView>

package huuah.tablelayout; import android.app.Activity;import android.os.Bundle;import android.widget.TableLayout;import android.widget.TextView;import android.view.View; import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.TableRow;import android.widget.TableRow.LayoutParams; public class tablelayout extends Activity implements OnClickListener {    /** Called when the activity is first created. */     //initialize a button and a counter    Button btn;    int counter = 0;     @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);         // setup the layout        setContentView(R.layout.main);         // add a click-listener on the button        btn = (Button) findViewById(R.id.Button01);        btn.setOnClickListener(this);             }     // run when the button is clicked    public void onClick(View view) {         // get a reference for the TableLayout        TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);         // create a new TableRow        TableRow row = new TableRow(this);         // count the counter up by one        counter++;         // create a new TextView        TextView t = new TextView(this);        // set the text to "text xx"        t.setText("text " + counter);         // create a CheckBox        CheckBox c = new CheckBox(this);         // add the TextView and the CheckBox to the new TableRow        row.addView(t);        row.addView(c);         // add the TableRow to the TableLayout        table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));     }}

原文出自 http://huuah.com/using-tablelayout-on-android/

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)打包及引用 aar 文件的方法
  2. Android中的Service的通信
  3. Android应用架构
  4. Android绘图系列(三)——自定义View绘制
  5. Android(安卓)Stuido 导出 APK
  6. 《Android(安卓)JNI》02 对java传进来的
  7. 安卓root漏洞分析——CVE-2009-1185
  8. Android开发管理手机短信
  9. android动画的透明度渐变、旋转动画、缩
  10. Android异步任务AsyncTask的使用与原理分