【发布时间】:2017-02-10 16:02:28
【问题描述】:
我正在尝试将片段放入 NestedSrollView。由于它是 FrameLayout 的孩子,我认为这是可能的。这是xml:
<android.support.v4.widget.NestedScrollView
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
第一次交易后一切正常,片段被附加到 NestedScrollView:
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_right, R.anim.fade_out, R.anim.slide_left, R.anim.fade_out)
.add(R.id.fragmentContainer, new RankingFragment(), RANKING_FRAGMENT)
.commit();
但是当我想替换第一个片段时,我得到了这个错误:
ScrollView 只能承载一个直接子节点
第二次交易:
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_right, R.anim.fade_out, R.anim.slide_left, R.anim.fade_out)
.replace(R.id.fragmentContainer, new com.steveq.photoquiz.ui.fragments.PreparationFragment(), PREPARATION_FRAGMENT)
.addToBackStack(PREPARATION_FRAGMENT)
.commit();
有人可以帮忙吗?
【问题讨论】:
-
我有同样的问题有什么帮助吗?
-
让我们看看我是如何在我的项目中解决这个问题的:github.com/SteveQQ/PhotoQuiz/blob/master/app/src/main/res/…
-
现在可以正常使用了
标签: java android android-fragments