【问题标题】:PreferenceFragment no scroll in CollapsingToolbarLayoutPreferenceFragment 在 CollapsingToolbarLayout 中没有滚动
【发布时间】:2016-03-03 05:52:23
【问题描述】:

我对 PreferenceFragment 和 CollapsingToolbarLayout 有疑问。我有一个基本布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.base.BaseActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbarLayout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/ctlLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"></android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:nestedScrollingEnabled="true"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fabFav"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="85dp"
    android:src="@android:drawable/ic_menu_save"
    app:layout_anchor="@id/appbarLayout"
    app:layout_anchorGravity="bottom|right|end"
    android:visibility="gone" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fabShare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_menu_share"
    app:borderWidth="0dp"
    app:layout_anchor="@id/appbarLayout"
    app:layout_anchorGravity="bottom|right|end"
    android:visibility="gone" />

<fragment
    android:id="@+id/search_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.eventum.raedictionary.fragments.SearchFragment"
    tools:layout="@layout/fragment_search"/>

问题是当我使用 PreferenceFragment 为 Framelayout 充气时,滚动不起作用,但使用普通 Fragment 可以正常工作。

        BaseSettingFragment settingsFragment = new BaseSettingFragment();

        fragmentTransaction = getFragmentManager().beginTransaction();

        fragmentTransaction.setCustomAnimations(R.transition.fade_in, R.transition.fade_out);

        fragmentTransaction.replace(R.id.fragment_container, settingsFragment);

        fragmentTransaction.commit();

我还没有找到任何解决此问题的方法,有人可以帮助我吗?

提前谢谢你。

PD:对不起我的英语。

【问题讨论】:

    标签: android android-collapsingtoolbarlayout preferencefragment


    【解决方案1】:

    PreferenceFragment 基于ListView,不支持CollapsingToolbarLayout 所需的嵌套滚动API。您可以改用Preference Support LibraryPreferenceFragmentCompat,它们基于RecyclerView 并且是否支持所需的嵌套滚动API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 2018-06-10
      • 2015-08-22
      • 1970-01-01
      • 2016-07-02
      • 2017-04-06
      相关资源
      最近更新 更多