回覆列表
  • 1 # A你的男朋友7

    android:below表示在某個控制元件下面,用程式碼首先是設定一個佈局引數,如下程式碼:

    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); }

  • 2 # 謝馨123

    android:below表示在某個控制元件下面,用程式碼首先是設定一個佈局引數,如下程式碼:

    小學剛上三年級 2015-03-13public class MyActivity extends Activity {/*** Called when the activity is first created.*/@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// setContentView(R.layout.main);RelativeLayout rl=new RelativeLayout(this);//建立TextView1TextView tv1=new TextView(this);tv1.setText("111111111111111111111111111");tv1.setTextSize(20);//設定 tv1 的 id ,後面規則要用到tv1.setId(1);//將tv1加入佈局rl.addView(tv1);//建立TextView2TextView tv2=new TextView(this);tv2.setText("2222222222222222222222222222");tv2.setTextSize(20);//建立RelativeLayout.LayoutParamsRelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);//新增規則 1為tv1的idparams.addRule(RelativeLayout.BELOW,1);//將tv2加入佈局 傳入引數paramsrl.addView(tv2,params);setContentView(rl);}

  • 中秋節和大豐收的關聯?
  • 1:3落後猛龍,勇士隊還有機會翻盤嗎?