android设计总结,android中框架设计的小总结

adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);

lv.setAdapter(adapter);

lv.setOnItemClickListener(this);

//------------------------------------------------------

Button btn1 = new Button(this);

btn1.setId(2);

btn1.setText("OK");

btn1.setOnClickListener(listener);

param = new RelativeLayout.LayoutParams(60, WC);

param.addRule(RelativeLayout.RIGHT_OF, 1);

param.leftMargin = 15;

param.topMargin = 20;

r_layout.addView(btn1, param);

//------------------------------------------------------

Button btn2 = new Button(this);

btn2.setId(3);

btn2.setText("Exit");

btn2.setOnClickListener(listener);

param = new RelativeLayout.LayoutParams(60, WC);

param.addRule(RelativeLayout.BELOW, 2);

param.addRule(RelativeLayout.ALIGN_LEFT, 2);

param.topMargin = 25;

r_layout.addView(btn2, param);

}

OnClickListener listener = new OnClickListener()

{

public void onClick(View v) {

if(v.getId() == 2)

tv.setText(selection);

else if(v.getId() == 3)

finish();

}

};

public void onItemClick(AdapterView> arg0, View arg1, int arg2, long arg3) {

// TODO Auto-generated method stub

setTitle(data[arg2]);

selection = data[arg2];

}

}

package com.misoo.ex08;

import android.app.Activity;

import android.os.Bundle;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.RelativeLayout;

import android.widget.EditText;

import android.widget.TableLayout;

import android.widget.TableRow;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

public class ex08 extends Activity implements OnClickListener {

private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

@Override public void onCreate(Bundle icicle) {

super.onCreate(icicle);

//根据下面所说的嵌套层次,首先是定义最大的view,并设定为目前布局(this值)

RelativeLayout r_layout = new RelativeLayout(this);

setContentView(r_layout);

//当书面上的一群view排成一个矩阵或者是表格形式时,就采用TableLayout来叙述其布局方式。

//接着定义第二个的TableLayout,并加入到r_layout里

TableLayout tableLayout = new TableLayout(this);

r_layout.addView(tableLayout, new RelativeLayout.LayoutParams(WC, WC));

tableLayout.setId(1);

//此程序采用的嵌套层次为:RelativeLayout->TableLayout->TableRow->EditText->Button->ImageView

//再定义第三个的TableRow,并加入到tableLayout里

TableRow tableRow1 = new TableRow(this);

tableLayout.addView(tableRow1, new TableLayout.LayoutParams(WC, WC));

//最后定义最小的view,并加入到tableRow里

ImageView iv = new ImageView(this);

tableRow1.addView(iv);

iv.setImageDrawable(getResources().getDrawable(R.drawable.star_big_on));

EditText edit1 = new EditText(this);

tableRow1.addView(edit1);

//-------------------------------------------------

TableRow tableRow2 = new TableRow(this);

tableLayout.addView(tableRow2, new TableLayout.LayoutParams(WC, WC));

ImageView iv2 = new ImageView(this);

iv2.setImageDrawable(getResources().getDrawable(R.drawable.gallery_photo_4));

tableRow2.addView(iv2);

EditText edit2 = new EditText(this);

tableRow2.addView(edit2);

//-------------------------------------------------

Button btn = new Button(this);

RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(WC, WC);

param.addRule(RelativeLayout.BELOW, 1);

param.topMargin = 20;

r_layout.addView(btn, param);

btn.setText("Exit");

btn.setOnClickListener(this);

}

public void onClick(View arg0) {

// TODO Auto-generated method stub

finish();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值