2015-07-28 1 views
9

Je fais un petit projet avec RecyclerView avec des éléments CardView à l'intérieur. J'ai créé une carte extensible (agrandie en appuyant sur un petit bouton à l'intérieur de la carte). Chaque carte contient toujours une partie visible (id: top_layout) et une partie extensible (id: expandable_part_layout). Problème: lorsque j'élargis le dernier élément ou élément qui après l'expansion a le bord inférieur sous le bord inférieur de RecyclerView (une partie de l'élément ou de l'élément développé est invisible pour l'utilisateur), RecyclerView doit faire défiler tous les éléments pour afficher l'élément entier J'ai élargi. J'ai essayé d'utiliser scrollToPosition et des méthodes similaires pour faire défiler jusqu'à la fin de la carte étendue, mais sans succès.Carte extensible RecyclerViewVoir

Donc, ma question est de savoir comment faire que, après avoir développé la carte, faites défiler vers le haut RecyclerView à propos de la hauteur de la partie étendue de la carte? - C'est mon idée, peut-être que quelqu'un a une meilleure solution.

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardCornerRadius="8px" 
    app:cardPreventCornerOverlap="false"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

    <RelativeLayout 
     android:id="@+id/top_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="false" 
     android:layout_alignParentTop="true" 
     > 
      <!-- some other controls --> 

      <ImageButton 
       android:id="@+id/card_header_inner_expand_btn" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:background="?android:selectableItemBackground" 
       android:clickable="true" 
       android:padding="6dp" 
       android:src="@drawable/expand_icon" /> 

    </RelativeLayout> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/expandable_part_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/top_layout" 
     android:animateLayoutChanges="true" 
     android:clickable="false" 
     android:visibility="gone"> 

     <RadioGroup 
      android:id="@+id/extened_stage_radiogroup" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:orientation="vertical"> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/> 

     </RadioGroup> 

     <!-- some other controls --> 

    </RelativeLayout> 
</RelativeLayout> 

+1

Avez-vous trouvé une solution à ce problème? J ai exactement le même problème. – Kerkhofsd

+0

Je m'intéresse aussi si vous avez trouvé une solution pour cela. – Allinone51

+0

Malheureusement, je n'ai pas encore trouvé de solution. – Darko

Répondre

1

Vous pouvez utiliser cette instance lib votre chemin auto développé, essayez ceci:

ÉTAPE 1: AJOUTZ dépendance à votre fichier build.gradle:

**compile 'com.github.traex.expandablelayout:library:1.2.2'** use instead of 
compile 'com.github.traex.expandablelayout:library:1.3' 

ÉTAPE 2: Ajouter au dessous Voir à la configuration de votre carte, card_layout Doit être l ook comme ceci:

<com.andexert.expandablelayout.library.ExpandableLayout 
    android:id="@+id/row_0" 
    xmlns:expandable="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    expandable:headerLayout="@layout/YOUR_CARD_VIEW_UI" 
    expandable:contentLayout="@layout/YOUR_CARD_VIEW_EXPANDED_UI"/> 

ÉTAPE 3: Dans votre définition de RecyclerView n'oubliez pas:

recList.setItemViewCacheSize(ITEMS_COUNT); 

hésitez pas à demander :-)

2

Qu'est-ce que tecnique utilisez-vous pour fais ça?

J'étais dans la même situation, mais pour moi, le problème étaient ces fonctions ExpandAndCollapseViewUtil.expand() et ExpandAndCollapseViewUtil.collapse() de ce tutoriel Diseño Android: Tarjetas con CardView donc je ne l'utilise pas. Au lieu de cela, je montre/cache la vue de la carte sans aucune animation.

+0

Solution assez simple, merci! –