求助:我该怎么办"包括(以XML)QUOT;以编程方式在我的应用程序的Andr​​oid? [英] help : how can i do "include(in xml)" programmatically in my app Android?

查看:155
本文介绍了求助:我该怎么办"包括(以XML)QUOT;以编程方式在我的应用程序的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的layout.xml该行:

i have in my layout.xml this lines :

<include android:id="@+id/promo1" android:layout_width="fill_parent"
         android:layout_height="fill_parent" layout="@layout/one_promo">
</include>
<include android:id="@+id/promo2" android:layout_width="fill_parent"
         android:layout_height="fill_parent" layout="@layout/one_promo">
</include>
<include android:id="@+id/promo3" android:layout_width="fill_parent"
         android:layout_height="fill_parent" layout="@layout/one_promo">
</include>

我想在我的Java code编程方式做到这一点。

I want to do this programmatically in my Java code.

请任何帮助吗?

在此先感谢

推荐答案

使用LayoutInflater,如图一所示。

Use LayoutInflater as i shown below

定义一个相对布局在XML

Define a Relative Layout in your xml

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

该地图在您的Java code

Map it in your Java code

RelativeLayout mynewlayout = (RelativeLayout) findById(R.id.mylayout);

使用布局充气

LayoutInflater layoutInflater = (LayoutInflater) 
        this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    
mynewlayout.addView(0, layoutInflater.inflate(R.layout.one_promo, this, false) );

这篇关于求助:我该怎么办&QUOT;包括(以XML)QUOT;以编程方式在我的应用程序的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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