【问题标题】:Fragments inside NestedScrollViewNestedScrollView 中的片段
【发布时间】: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();

有人可以帮忙吗?

【问题讨论】:

标签: java android android-fragments


【解决方案1】:

尝试将这个 attr 'android:fillViewport' 设置为 true,然后你会发现你的 Fragment 已附加到活动中

<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"/>

【讨论】:

  • 感谢您的帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-07
  • 2017-03-30
相关资源
最近更新 更多