2015-07-28 24 views
9

Tôi tạo một dự án nhỏ với RecyclerView với các mục CardView bên trong. Tôi đã tạo thẻ mở rộng (được mở rộng bằng cách nhấn vào nút nhỏ bên trong thẻ). Mỗi thẻ luôn chứa phần hiển thị (id: top_layout) và phần có thể mở rộng (id: expandable_part_layout).RecyclerView card mở rộngXem

Vấn đề là khi tôi mở rộng mục hoặc mục cuối cùng sau khi mở rộng có cạnh dưới bên dưới cạnh dưới của RecyclerView (một số phần của mục hoặc mục mở rộng là vô hình cho người dùng) RecyclerView sẽ cuộn lên tất cả các mục để hiển thị toàn bộ mục Tôi mở rộng. Tôi đã thử sử dụng scrollToPosition và các phương pháp tương tự để cuộn đến cuối thẻ mở rộng nhưng không thành công.

Vì vậy, câu hỏi của tôi là làm thế nào để làm điều đó sau khi tôi mở rộng thẻ cuộn lên RecyclerXem chiều cao của phần mở rộng của thẻ? - Đó là ý tưởng của tôi, có lẽ ai đó có giải pháp tốt hơn.

<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

Bạn có tìm thấy giải pháp cho vấn đề này không? Tôi có chính xác cùng một vấn đề. – Kerkhofsd

+0

Tôi cũng quan tâm nếu bạn tìm thấy giải pháp cho việc này. – Allinone51

+0

Rất tiếc, tôi chưa tìm thấy giải pháp. – Darko

Trả lời

1

Bạn có thể sử dụ lib này tự phát triển theo cách của bạn, hãy thử này:

BƯỚC 1: Thêm dưới đây phụ thuộc vào build.gradle tập tin của bạn:

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

BƯỚC 2: Thêm bên dưới Xem bố cục thẻ của bạn, card_layout Phải là l ook như thế này:

<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"/> 

BƯỚC 3: Trong bạn xác định của RecyclerView nhớ:

recList.setItemViewCacheSize(ITEMS_COUNT); 

đừng ngần ngại hỏi :-)

2

tecnique gì bạn đang sử dụng để làm việc đó đi?

tôi ở trong tình trạng tương tự nhưng đối với tôi vấn đề là các chức năng này ExpandAndCollapseViewUtil.expand()ExpandAndCollapseViewUtil.collapse() từ hướng dẫn này Diseño Android: Tarjetas con CardView vì vậy tôi đã không sử dụng nó. Thay vào đó, tôi chỉ hiển thị/ẩn chế độ xem của chế độ xem mà không có bất kỳ hoạt ảnh nào.

+0

Giải pháp khá đơn giản, cảm ơn bạn! –