帮助:我该怎么做;包括(在xml中)“;在我的应用程序Android中编程?

帮助:我该怎么做;包括(在xml中)“;在我的应用程序Android中编程?,android,android-layout,android-xml,Android,Android Layout,Android Xml,我的layout.xml中有以下几行: <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_p

我的layout.xml中有以下几行:

<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代码中以编程方式实现这一点

有什么需要帮忙的吗


提前感谢

使用LayoutInflater,如下所示

在xml中定义相对布局

<RelativeLayout android:id="@+id/mylayout" android:layout_width="fill_parent"
         android:layout_height="fill_parent" />
使用布局充气机

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

使用LayoutFlater,如下所示

在xml中定义相对布局

<RelativeLayout android:id="@+id/mylayout" android:layout_width="fill_parent"
         android:layout_height="fill_parent" />
使用布局充气机

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

谢谢sankar的回复,我想我会将我的include集成到xml中,但我需要更改每个include的属性布局,解释:我的布局xml中有五个include,我想通过编程更改每个include的布局属性,可以吗?@houcine:欢迎您,试着告诉我你是否到达了目的地?谢谢sankar的回复,我想我会在xml中集成我的包含,但我需要更改每个包含的属性布局,说明:我的布局xml中有五个包含,我想通过编程更改每个包含的布局属性,有可能吗?@hounice:是的,有可能使用上面所示的LayoutInflater,然后在addview方法的第一个参数mynewlayout.addview(0,LayoutInflater.inflate(R.layout.one_promo,this,false))中添加并更改child的值;然后,对于我的第二个例子,我在这里展示了mynewlayout.addView(1,layoutInflater.inflate(R.layout.one_promo,this,false));我想我不需要在我的XML代码中添加relativeLayout,因为我的HorizontalScrollView上已经有一个linearLayout,你认为呢?谢谢sankar的回复,我想我会将我的Include集成到XML中,但我需要更改每一个的属性布局,解释:我的布局XML中有五个Include,我想以编程方式更改每一个的布局属性,可以吗?@houcine:欢迎您,无论您是否到达目的地,请尝试告诉我您是否到达目的地?谢谢sankar的回复,我想我会将我的包含集成到xml中,但我需要更改每一个的属性布局,说明:我的布局xml中有五个包含,我想以编程方式更改每个包含的布局属性,是否可行?@hounice:是的,可以如上面所示使用LayoutFlater,然后在addview方法的第一个参数mynewlayout.addview(0,LayoutFlater.inflate)中添加更改child的值(R.layout.one_promo,this,false));然后,对于我的第二个示例,我在这里展示了mynewlayout.addView(1,LayoutFlater.inflate(R.layout.one_promo,this,false));我认为我不需要在XML代码中添加relativeLayout,因为我的HorizontalScrollView上已经有一个线性布局,你认为呢??