PreferenceFragment在CollapsingToolbarLayout中没有滚动 [英] PreferenceFragment no scroll in CollapsingToolbarLayout
问题描述
我对PreferenceFragment和CollapsingToolbarLayout有问题.我有一个基本布局:
I have a problem with PreferenceFragment and CollapsingToolbarLayout. I have a base layout:
<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可以正常工作.
The problem is when I inflate the Framelayout with a PreferenceFragment the scroll doesn't work but with a normal Fragment works properly.
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();
我没有找到解决此问题的任何方法,有人可以帮助我吗?
I haven't found any solutions for this problem, can anyone help me?
谢谢.
PD:对不起,我的英语.
PD: Sorry for my English.
推荐答案
PreferenceFragment
基于ListView
,它不支持CollapsingToolbarLayout
所需的嵌套滚动API.您可以改为使用首选项支持库和
PreferenceFragment
is based on ListView
, which does not support the nested scrolling APIs required for CollapsingToolbarLayout
. You can instead use the Preference Support Library and PreferenceFragmentCompat, which is based on RecyclerView
and does support the nested scrolling APIs required.
这篇关于PreferenceFragment在CollapsingToolbarLayout中没有滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!