2011-07-24 8 views
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レイアウトが定義されています。誰かがビューのいずれかを読み込み、そこから値をセット/取得する方法を教えてください。

答えて

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); 
+0

私は申し訳ありませんが、このコードをどのように使用すればよいか把握できません。 –

+0

詳細を教えてください。(各ifの後で)各テストの後、これを行う(レイアウトを膨らませる)。 –

関連する問題