0

J'ai une mise en page contenant un RecyclerView et une mise en page pour la gestion montrant plus d'éléments. Lorsqu'un ou plusieurs éléments sont reçus en appuyant sur le bouton "Afficher plus", l'adaptateur est notifié et les éléments sont ajoutés sur RecyclerView. Mais le problème est, que hauteur de RecyclerView après qu'un élément a été ajouté n'est pas développé. Cette disposition fait partie d'un fragment contenu dans un ViewPager sous CollapsingToolbarLayout.RecyclerView n'augmente pas sa hauteur lorsqu'un élément est ajouté sur l'adaptateur

La structure de mise en page du fragment:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:background="#f5f5f5"> 

<com.github.rahatarmanahmed.cpv.CircularProgressView 
    android:id="@+id/progress_view" 
    android:layout_width="45dp" 
    android:layout_height="45dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="40dp" 
    app:cpv_animAutostart="true" 
    app:cpv_indeterminate="true" 
    app:cpv_thickness="4dp"/> 

<LinearLayout 
    android:id="@+id/list_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/reviews_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

    <FrameLayout 
     android:id="@+id/show_more_container" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#eee"> 

     <TextView 
      android:id="@+id/show_more_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Show More" 
      android:textSize="15sp" 
      android:textColor="@color/colorPrimary"/> 

     <com.github.rahatarmanahmed.cpv.CircularProgressView 
      android:id="@+id/show_more_progress_view" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:visibility="invisible" 
      app:cpv_animAutostart="true" 
      app:cpv_indeterminate="true" 
      app:cpv_thickness="3dp"/> 

    </FrameLayout> 

</LinearLayout> 

</FrameLayout> 

Et l'état actuel est quelque chose comme ceci:

State

  • Et la partie noire de l'image est la hauteur disponible de l'appareil.
+0

Avez-vous essayé d'appeler "requestLayout" sur le RecyclerView? –

+0

Ouais, ne fonctionnait pas non plus. – gkanellis

Répondre

0
  1. changez le layout_height de linearlayout en match_parrent.
  2. changez la layout_height de recyclerview en match_parrent.
  3. changez la hauteur de votre objet recyclerviews en wrap_content.

essayer cette

+0

La définition de layout_height de linearlayout à match_parrent ne fonctionnait pas. Si je mets le layout_height de recyclerview à match_parrent alors le bouton "Show more" est caché en raison du comportement de LinearLayout. – gkanellis

+0

alors changez la linearlayout à la disposition relative. –

0

Remplacer cette

<LinearLayout 
     android:id="@+id/list_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

à

<LinearLayout 
      android:id="@+id/list_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

aussi changer la hauteur Recyclerview à match_parent

+0

Ne fonctionne pas. Still recyclerView est seulement scrollable est la zone où le premier élément est ajouté. – gkanellis

+0

Modifier également la hauteur de la vue Recycler en match_parent – Saneesh

0

Changer votre LinearLayout à un RelativeLayout, ancre FrameLayout au parent bas et RecyclerView au-dessus de votre FrameLayout comme suit:

<RelativeLayout android:id="@+id/list_container" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/reviews_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/show_more_container" /> 

    <FrameLayout 
     android:id="@+id/show_more_container" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:background="#eee"> 

     <TextView 
      android:id="@+id/show_more_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Show More" 
      android:textSize="15sp" 
      android:textColor="@color/colorPrimary"/> 

     <com.github.rahatarmanahmed.cpv.CircularProgressView 
      android:id="@+id/show_more_progress_view" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:visibility="invisible" /> 

    </FrameLayout> 

</RelativeLayout> 

changement RecyclerView hauteur match_parent

0

Cochez cette mise en page modifiée. Ajouter du poids à recyclerview et le bouton va le faire fixer dans une position particulière.Espagne que cela fonctionne pour vous.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:background="#f5f5f5"> 

<com.github.rahatarmanahmed.cpv.CircularProgressView 
    android:id="@+id/progress_view" 
    android:layout_width="45dp" 
    android:layout_height="45dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="40dp" 
    app:cpv_animAutostart="true" 
    app:cpv_indeterminate="true" 
    app:cpv_thickness="4dp"/> 

<LinearLayout 
    android:id="@+id/list_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/reviews_list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.9"/> 

    <FrameLayout 
     android:id="@+id/show_more_container" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:background="#eee"> 

     <TextView 
      android:id="@+id/show_more_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Show More" 
      android:textSize="15sp" 
      android:textColor="@color/colorPrimary"/> 

     <com.github.rahatarmanahmed.cpv.CircularProgressView 
      android:id="@+id/show_more_progress_view" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:visibility="invisible" 
      app:cpv_animAutostart="true" 
      app:cpv_indeterminate="true" 
      app:cpv_thickness="3dp"/> 

    </FrameLayout> 

</LinearLayout>