我可以设置"安卓la​​yout_below"在运行时,通过编程? [英] Can I set "android:layout_below" at runtime, programmatically?

查看:153
本文介绍了我可以设置"安卓la​​yout_below"在运行时,通过编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时创建一个相对的布局时,设置的 Android的等效是否有可能:layout_below 编程

Is it possible when creating a relative layout at runtime, to set the equivalent of android:layout_below programmatically?

推荐答案

是:

RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);

p.addRule(RelativeLayout.BELOW, R.id.below_id);

viewToLayout.setLayoutParams(p);

首先code。通过指定的高度和宽度会创建一个新的布局PARAMS。该 addRule 方法添加XML属性格式安卓相当于:layout_below 。然后,你只需要调用查看#setLayoutParams 在视图你想拥有这些PARAMS。

First the code creates a new layout params by specifying the height and width. The addRule method adds the equivalent of the xml propery android:layout_below. Then you just call View#setLayoutParams on the view you want to have those params.

这篇关于我可以设置"安卓la​​yout_below"在运行时,通过编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆