我想以编程方式设置这些属性: -
android:layout_toEndOf="@+id/imageView1"
android:layout_toRightOf="@+id/imageView1"
答案 0 :(得分:14)
View的父级当然必须是RelativeLayout。然后就可以了
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF, R.id.imageView1);
params.addRule(RelativeLayout.END_OF, R.id.imageView1);
并致电
view.setLayoutParams(params);