充气Android的意见 [英] inflating views android
本文介绍了充气Android的意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有有一个固定的页眉和页脚这个main.xml中的布局。主体内容具有根据接收到的参数来改变。
I have this main.xml layout which has a fixed header and footer. The body content has to change based on the parameters received.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#FFFFFF"
android:id="@+id/main_view">
<com.HeaderView
android:id="@+id/HeaderView"
android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<com.FooterView
android:id="@+id/FooterView"
android:layout_alignParentBottom="true" android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/BodyView"
android:layout_below="@id/HeaderView"
android:layout_above="@id/FooterView"/>
</RelativeLayout>
根据下面的条件,我需要加载BodyView在main.xml中。
Based on the below conditions I need to load the BodyView in the main.xml.
If parameter == Apple
then load layout AppleView in the BodyView
if parameter == Bat
then load layout BatView in the BodyView
我有定义AppleView和BatView XML布局。从中可能有人请指导我,我怎么可以装载的意见,并设置/获取值转换成/。
I have AppleView and BatView xml layout defined. Could somebody please guide me as to how I can load either of the views and set/get values into/from it.
推荐答案
下面是膨胀的一个例子,希望这是你所需要的。
Here is an example of inflating, hope this is what you need.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.temp, null);
RelativeLayout rl = (RelativeLayout)findViewById(R.id.glavenfrejm);
RelativeLayout.LayoutParams parametri = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
parametri.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rl.addView(v, parametri);
这篇关于充气Android的意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文