如何以编程方式在RelativeLayout中部署视图?
<RelativeLayout...> <TextView ... android:id="@+id/label1" /> <TextView ... android:id="@+id/label2" android:layout_below: "@id/label1" /></RelativeLayout>
TextView
RelativeLayout layout = new RelativeLayout(this);TextView label1 = new TextView(this);TextView label2 = new TextView(this);... layout.addView(label1);layout.addView(label2);setContentView(layout);
RelativeLayout layout = new RelativeLayout(this);TextView tv1 = new TextView(this);tv1.setText("A");TextView tv2 = new TextView(this); tv2.setText("B");RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT); lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());layout.addView(tv1); layout.addView(tv2, lp);
慕姐4208626
炎炎设计
相关分类