开发者

programmatically set "Layout to right of" property in android

I want to set property "Layout to right of" of control at runtime in android. Act开发者_如何学编程ually I want to adjust controls when screen changes orientation.


You can do something like this:

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.RIGHT_OF, view.getId());


If you define a new LayoutParams, you lose other rules.

So if you just want to change or add a rule, do this:

 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();
 params.addRule(RelativeLayout.RIGHT_OF, targetView.getId());
 view.setLayoutParams(params);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜