如何使用布局膨胀一个视图 [英] How to inflate one view with a layout

查看:30
本文介绍了如何使用布局膨胀一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 XML 定义的布局.它还包含:

I have a layout defined in XML. It contains also:

<RelativeLayout
    android:id="@+id/item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

我想用其他 XML 布局文件来扩充这个 RelativeView.我可能会根据情况使用不同的布局.我该怎么做?我正在尝试

I would like to inflate this RelativeView with other XML layout file. I may use different layouts depending on a situation. How should I do it? I was trying different variations of

RelativeLayout item = (RelativeLayout) findViewById(R.id.item);
item.inflate(...)

但没有一个工作正常.

推荐答案

我不确定我是否听过您的问题 - 您是否尝试将子视图附加到 RelativeLayout?如果是这样,你想做一些事情:

I'm not sure I have followed your question- are you trying to attach a child view to the RelativeLayout? If so you want to do something along the lines of:

RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child, null);
item.addView(child);

这篇关于如何使用布局膨胀一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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