http://wenku.baidu.com/link?url=vR6Rkj8jwPMcuBB0S2PAYtvKLRZavGw99LAoMtxW9Z737Utkk7t4sK4YR16pU8FO4obwvDkbkTLHki16pkhqs_SQa2u7DhpdEeT42P-WTDC
2024-09-20 01:04:45
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
RelativeLayout rl=new RelativeLayout(this);
//创建TextView1
TextView tv1=new TextView(this);
tv1.setText("111111111111111111111111111");
tv1.setTextSize(20);
//设定 tv1 的 id ,后面规则要用到
tv1.setId(1);
//将tv1加入布局
rl.addView(tv1);
//创建TextView2
TextView tv2=new TextView(this);
tv2.setText("2222222222222222222222222222");
tv2.setTextSize(20);
//创建RelativeLayout.LayoutParams
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//添加规则 1为tv1的id
params.addRule(RelativeLayout.BELOW,1);
//将tv2加入布局 传入参数params
rl.addView(tv2,params);
setContentView(rl);
}
2024-09-20 00:32:06