我是靠谱客的博主 单身黑猫,这篇文章主要介绍Android 动态加载布局后设置控件属性,现在分享给大家,希望可以做个参考。

//加载布局
LayoutInflater.from(context).inflate(R.layout.navigation_bar_layout, this);

//寻找控件
LinearLayout lvNavigationBar = findViewById(R.id.navigation_bar_lv);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) lvNavigationBar.getLayoutParams();

//设置属性 — 边距
params.topMargin = 10;

lvNavigationBar.setLayoutParams(params);


注意事项:

1.RelativeLayout.LayoutParams是控件外层的布局

2.topMargin 单位 为 px

 

 

最后

以上就是单身黑猫最近收集整理的关于Android 动态加载布局后设置控件属性的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部