【问题标题】:add Viewpager dynamically in a framelayout在框架布局中动态添加 Viewpager
【发布时间】:2012-12-06 11:38:51
【问题描述】:

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

例如,在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。可以吗??

【问题讨论】:

    标签: android android-viewpager android-framelayout


    【解决方案1】:

    我想用 id 内容替换框架布局 在运行时将片段保存到片段的查看器。是吗 可能吗??

    您不能将 Fragment 替换为像 ViewPager 这样的简单 ViewGroup,但由于 4.2 中的新变化,您可以将 ViewPager 本身放入 Fragment 并使用嵌套的 @987654328 @ 作为ViewPager 的孩子。然后您可以将初始的Fragment 替换为包含ViewPagerFragment

    参见this guide,嵌套的Fragments 也可通过兼容性包用于较低的API。有关实现示例,请参阅this question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多