2013-03-08 92 views
1
<LinearLayout 
    android:id="@+id/linear2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <ViewFlipper 
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <include android:id="@+id/include1" layout="@layout/fb_list1"/> 
    <include android:id="@+id/include2" layout="@layout/fb_list2"/> 
    </ViewFlipper> 
</LinearLayout> 

這是我的主要佈局。我在鰭狀視圖中有2個視圖,我想動態添加第三個視圖。我應該怎麼做?如何動態添加視圖到鰭狀視圖

回答

0
// this gets you the LinearLayout 
LinearLayout ll = (LinearLayout) findViewById(R.id.linear2); 

// Create your view and add it 
ViewFlipper vf = new ViewFlipper(this); 
ll.addView(vf, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
2
private static final LayoutParams mLop = 
     new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
             LinearLayout.LayoutParams.WRAP_CONTENT); 

這裏是你必須動態地創建你的腳蹼視圖....

mFlipper = new ViewFlipper(mContext); 
      mFlipper.setLayoutParams(mLop); 
      this.addView(mFlipper); 

這裏是腳蹼視圖中添加視圖

vm.setLayoutParams(mLop); 
       mFlipper.addView(vm);