Android 在框架布局中动态添加Viewpager

Android 在框架布局中动态添加Viewpager,android,android-viewpager,android-framelayout,Android,Android Viewpager,Android Framelayout,是否可以使用.replace()替换FrameLayout中的片段以使用ViewPager?因为两者都是视图组 例如,在xml中,我只有 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_hei

是否可以使用
.replace()
替换FrameLayout中的片段以使用ViewPager?因为两者都是视图组

例如,在xml中,我只有

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

<FrameLayout
    android:id ="@+id/content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

我想用id内容替换FrameLayout,它在运行时将一个片段保存到片段的ViewPager中。有可能吗

我想用以下id内容替换framelayout: 在运行时将片段保存到片段的viewpager。它是 可能吗

您不能用简单的
视图组
来代替
片段
,就像
查看页面
,但由于4.2中的新更改,您可以将
查看页面
本身放入
片段
,并使用嵌套的
片段
作为
查看页面
的子项。然后,您可以将初始的
Fragment
替换为保存
ViewPager
Fragment

请参阅,嵌套的
片段
也可通过兼容包供低级API使用。有关实现示例,请参见

我想用以下id内容替换framelayout: 在运行时将片段保存到片段的viewpager。它是 可能吗

您不能用简单的
视图组
来代替
片段
,就像
查看页面
,但由于4.2中的新更改,您可以将
查看页面
本身放入
片段
,并使用嵌套的
片段
作为
查看页面
的子项。然后,您可以将初始的
Fragment
替换为保存
ViewPager
Fragment

请参阅,嵌套的
片段
也可通过兼容包供低级API使用。有关实现示例,请参见