android简单demo学习系例之排版(TableLayout)[code-based]
2009-02-06 20:56
706 查看
程序用到的图片
bg1.jpg
bg2.jpg
程序运行效果
对应的UI-TREE
相对布局的使用只有注意到控件ID就不难理解与编码
代码:
bg1.jpg
bg2.jpg
程序运行效果
对应的UI-TREE
相对布局的使用只有注意到控件ID就不难理解与编码
代码:
package com.shcolar.luo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TableLayout; import android.widget.TableRow; /** * 简单的TableLayoutDemo 基于code-based * @author shcolar.luo * */ public class TableLayoutDemo extends Activity implements OnClickListener{ private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //ViewGroup1-根节点 包含ViewGroup2-TableLayout 与 View-Button RelativeLayout sRLayout = new RelativeLayout(this); setContentView(sRLayout); //ViewGroup2 TableLayout sTLayout = new TableLayout(this); //设置ID,相对布局用到 sTLayout.setId(1); sRLayout.addView(sTLayout, new TableLayout.LayoutParams(WC, WC)); //ViewGroup2的第一行 TableRow sRow1 = new TableRow(this); sTLayout.addView(sRow1, new TableLayout.LayoutParams(WC, WC)); ImageView sImageView1 = new ImageView(this); sImageView1.setImageDrawable(this.getResources().getDrawable(R.drawable.bg1)); EditText sEditText1 = new EditText(this); sRow1.addView(sImageView1); sRow1.addView(sEditText1); //ViewGroup2的第二行 TableRow sRow2 = new TableRow(this); sTLayout.addView(sRow2, new TableLayout.LayoutParams(WC, WC)); ImageView sImageView2 = new ImageView(this); sImageView2.setImageDrawable(this.getResources().getDrawable(R.drawable.bg2)); EditText sEditText2 = new EditText(this); sRow2.addView(sImageView2); sRow2.addView(sEditText2); Button sExitButton = new Button(this); sExitButton.setText("退出"); sExitButton.setOnClickListener(this); RelativeLayout.LayoutParams sLayoutParams = new RelativeLayout.LayoutParams(WC, WC); sLayoutParams.addRule(RelativeLayout.BELOW, 1); sLayoutParams.topMargin = 20; //sExitButton相对于ViewGroup2排版 sRLayout.addView(sExitButton, sLayoutParams); } /** * 点击事件处理 */ public void onClick(View v) { this.finish(); } }
相关文章推荐
- android简单demo学习系例之排版(TableLayout)[xml-based]
- android简单demo学习系例之排版(LinearLayout)[code-based]
- android简单demo学习系例之排版(LinearLayout)[xml-based]
- APIDemo学习笔记——Android上几种简单的Animation使用方法(二)
- android学习——使用TableLayout动态生成表格,并为tablerow中的列添加点击监听
- android学习--Android五大布局对象---FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout.
- Android TableLayout布局学习
- android学习——使用TableLayout动态生成表格,并为tablerow中的列添加点击监听
- Android学习之简单理解布局的layout_gravity和gravity属性
- android开发学习之 简单的demo SharedPreferences 的登陆账号密码保存和按键退出提醒
- Android学习第四天之表格布局TableLayout
- 一个简单的demo学习Android远程Service(AIDL的使用)
- Android表格布局TableLayout简单实现(Java动态添加,设置边框,删除数据(单行,多行))
- [转]Android TableLayout学习
- Android学习:TableLayout使用
- Android学习 9-> 表格布局TableLayout和网格布局GridLayout
- Android学习(十五)五布局之表格布局TableLayout
- Android TableLayout官方文档 例子学习笔记
- APIDemo学习笔记——Android上几种简单的Animation使用方法(二)
- Android 排版库:FlexboxLayout简单使用。