加上现有的XML编程布局 [英] add an existing XML layout programatically

查看:179
本文介绍了加上现有的XML编程布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创造一些文字和图片浏览编程一个新的RelativeLayout然后将其添加到父布局。问题:是否有可能在XML定义布局,然后只需将其添加到父编程?将是一个更快的方法。

I'm going to create a new RelativeLayout with some Text and Image Views programatically and then add it to a parent layout. The question: is it possible to define that layout in XML and then just add it to the parent programatically? Would be a faster way..

推荐答案

使用通货膨胀:

final LayoutInflater lyInflaterForPanel = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout lLayoutPanel = (LinearLayout) lyInflaterForPanel.inflate(
                R.layout.my_row, null);

这很适合我。

这篇关于加上现有的XML编程布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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