<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 :(得分: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);
答案 1 :(得分:0)
addView方法应该适用于此。但是,您考虑过使用FragmentPagerAdapter吗?
答案 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));