红色childview2位于白色view左边20dp

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View childView = findViewById(R.id.child1);
RelativeLayout parent = findViewById(R.id.parent);
RelativeLayout.LayoutParams lps = (RelativeLayout.LayoutParams) childView.getLayoutParams();
lps.rightMargin = dip2px(this, 20.0f);
lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

View childView2 = findViewById(R.id.child2);
RelativeLayout.LayoutParams lps2 = (RelativeLayout.LayoutParams) childView2.getLayoutParams();
//lps2.addRule(RelativeLayout.BELOW,R.id.child1);
lps2.rightMargin = dip2px(this, 20.0f);
lps2.addRule(RelativeLayout.LEFT_OF, R.id.child1);
}
---------------------

posted @ 2019-08-19 20:18  水至清明  阅读(57)  评论(0编辑  收藏  举报