我正在尝试在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);
}
希望这对某人有所帮助