是否有可能取代片段与 .replace一个的FrameLayout()
使用ViewPager?因为两者都是ViewGroups。
例如,在XML中,我只有
<?XML版本=1.0编码=UTF-8&GT?;<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT/><的FrameLayout 机器人:ID =@ + ID /内容 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT/>
和我想换成与在运行时保持一个片段一个片段ViewPager的标识内容的FrameLayout。是否有可能?
解决方案我想更换ID的内容是这样的的FrameLayout 拿着片段在运行时片段的viewpager。是吗 可能吗?
您不能取代片段
用一个简单的的ViewGroup
像 ViewPager
,但由于在4.2的新变化,你可以把 ViewPager
本身在片段
并使用嵌套的片段
作为的 ViewPager
的孩子。然后,你可以更换初始片段
与片段
保存在 ViewPager
。
请参阅本指南,嵌套的片段
也可通过兼容包下的API。见this问题一个实现的例子。
Is it possible to replace a fragment in a FrameLayout with the .replace()
to use a ViewPager? since both are ViewGroups.
For example, in xml, I have only
<?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" />
and I would like to replace the FrameLayout with id content that is holding a fragment to a ViewPager of fragments in runtime. Is it possible??
解决方案i would like to replace the framelayout with id content that is holding a fragment to a viewpager of fragments in runtime. is it possible??
You can't replace a Fragment
with a simple ViewGroup
like a ViewPager
, but thanks to the new changes in 4.2 you could put the ViewPager
itself in a Fragment
and use nested Fragments
as the children of the ViewPager
. Then you could replace the initial Fragment
with the Fragment
that holds the ViewPager
.
See this guide, nested Fragments
are also available to lower APIs through the compatibility package. See this question for an implementation example.
上一篇:动态改变的android gridview的列数?动态、android、gridview
下一篇:Genymotion - 哪个IP设置etc / hosts文件通过域名访问主机的本地Web服务器?主机、服务器、域名、文件