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 个视图,我想动态添加第三个视图。我该怎么做?

4

3 回答 3

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);
于 2013-03-08T13:32:35.440 回答
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));
于 2013-03-08T13:20:27.923 回答
0

addView方法应该适用于此但是,您是否考虑过使用FragmentPagerAdapter

于 2013-03-08T13:15:23.073 回答