gpt4 book ai didi

java - NestedScrollView 中的 fragment

转载 作者:太空狗 更新时间:2023-10-29 14:44:31 26 4
gpt4 key购买 nike

我正在尝试将 fragment 放入 NestedSrollView。因为它是 FrameLayout 的 child ,所以我认为这是可能的。这是 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>

第一次交易后一切正常, fragment 附加到 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();

但是当我想替换第一个 fragment 时,我得到了这个错误:

ScrollView can host only one direct child

第二笔交易:

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();

有人可以帮忙吗?

最佳答案

尝试将此属性 'android:fillViewport' 设置为 true,然后您会发现您的 fragment 已附加到 Activity

<android.support.v4.widget.NestedScrollView
android:id="@+id/feed_club_tab_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/feedui_pager_tab"
android:fillViewport="true"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"/>

关于java - NestedScrollView 中的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42163655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com