0
我想要做這樣的事情的時候動態地添加視圖XML ATTR:動態調整視圖查看?
android:layout_alignRight="@+id/myView1">
我的活動代碼:
button1.setOnClickListener(new View.OnClickListener(){
@Override public void onClick(View v) {
RelativeLayout ll = (RelativeLayout)findViewById(R.id.aincrad);
TextView view = new TextView(Activity.this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_RIGHT,R.id.Btn1Holder);
view.setText("testing...");
view.setLayoutParams(layoutParams);
ll.addView(view, layoutParams);
}});
結果應該一致Btn1Holder
的新的TextView呆在
好吧我改變了序列,但仍然沒有對齊,我使用'layoutParams.addRule(RelativeLayout.ALIGN_RIGHT,R .id.Btn1Holder); ' –
在你粘貼的代碼中你沒有使用addRule .. – fedepaol
更新的問題 –