0

J'essaye de construire PreferenceFragment dans . Le problème est qu'il y a trop d'éléments dans PreferenceFragment et ils ne sont pas affichés. Il semble que NestedScrollView ne fonctionne pas avec ces fragments. La solution here ne fonctionne pas pour moi, car je ne peux pas utiliser la bibliothèque compat pour d'autres raisons. Comment puis-je résoudre ce problème?Préférence de défilementFragment avec CollapsingToolbarLayout

code:

<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> 
+0

Que voulez-vous dire par la bibliothèque compat? – Cochi

+0

je veux dire la bibliothèque de préférences de soutien –

Répondre

1

bien après une longue période je me suis dit que PreferenceFragment utilise ListView pour afficher ses éléments qui, à son tour, ne fonctionne pas à l'intérieur NestedScrollView. Je l'ai résolu en remplaçant la méthode onViewCreated dans PreferenceFragment:

@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); 
} 

Hope this helps quelqu'un