0

ヘッダーとフッターが固定されたこの main.xml レイアウトがあります。本文の内容は、受け取ったパラメーターに基づいて変更する必要があります。

    <?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>

以下の条件に基づいて、main.xml に BodyView をロードする必要があります。

If parameter == Apple 
  then load layout AppleView in the BodyView
if parameter == Bat
  then load layout BatView in the BodyView

AppleView と BatView の xml レイアウトが定義されています。ビューのいずれかをロードして値を設定/取得する方法について、誰かが私を案内してくれませんか。

4

1 に答える 1

6

これが膨張の例です。これが必要なものであることを願っています。

  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);
于 2011-07-24T21:24:06.270 に答える