android:below表示在某個控件下面,用代碼首先是設置一個布局參數,如下代碼:
4
評論分享
舉報
小學剛上三年級2015-03-13
publicclassMyActivityextendsActivity{/***Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//setContentView(R.layout.main);RelativeLayoutrl=newRelativeLayout(this);//創建TextView1TextViewtv1=newTextView(this);tv1.setText("111111111111111111111111111");tv1.setTextSize(20);//設定tv1的id,后面規則要用到tv1.setId(1);//將tv1加入布局rl.addView(tv1);//創建TextView2TextViewtv2=newTextView(this);tv2.setText("2222222222222222222222222222");tv2.setTextSize(20);//創建RelativeLayout.LayoutParamsRelativeLayout.LayoutParamsparams=newRelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);//添加規則1為tv1的idparams.addRule(RelativeLayout.BELOW,1);//將tv2加入布局傳入參數paramsrl.addView(tv2,params);setContentView(rl);}
android:below表示在某個控件下面,用代碼首先是設置一個布局參數,如下代碼:
publicclassMyActivityextendsActivity{/***Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);//setContentView(R.layout.main);RelativeLayoutrl=newRelativeLayout(this);//創建TextView1TextViewtv1=newTextView(this);tv1.setText("111111111111111111111111111");tv1.setTextSize(20);//設定tv1的id,后面規則要用到tv1.setId(1);//將tv1加入布局rl.addView(tv1);//創建TextView2TextViewtv2=newTextView(this);tv2.setText("2222222222222222222222222222");tv2.setTextSize(20);//創建RelativeLayout.LayoutParamsRelativeLayout.LayoutParamsparams=newRelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);//添加規則1為tv1的idparams.addRule(RelativeLayout.BELOW,1);//將tv2加入布局傳入參數paramsrl.addView(tv2,params);setContentView(rl);}