滚动首选项片段与折叠工具栏布局



我正在尝试在CollapsingToolbarLayout中构建PreferenceFragment。问题是PreferenceFragment中的元素太多,并且没有显示它们。似乎NestedScrollView没有使用这些片段。这里的解决方案对我不起作用,因为出于其他原因我无法使用兼容库。如何解决此问题?

法典:

<android.support.v4.widget.NestedScrollView 
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_user_profile">
<FrameLayout
android:id="@+id/user_profile_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>

好吧,过了很长时间,我发现PreferenceFragment使用ListView来显示其元素,而这些元素又在NestedScrollView中不起作用。我通过覆盖PreferenceFragment中的onViewCreated方法解决了它:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final ListView lv = (ListView) view.findViewById(android.R.id.list);
if (lv != null)
ViewCompat.setNestedScrollingEnabled(lv, true);
}

希望这对某人有所帮助

最新更新