Dar*_*rko 9 android android-recyclerview recyclerview-layout
我使用带有CardView项目的RecyclerView制作小项目.我创建了可扩展卡(通过按下卡内的小按钮进行扩展).每张卡片始终包含可见部分(id:top_layout)和可扩展部分(id:expandable_part_layout).
问题是当我展开最后一个项目或项目后,扩展后底部边缘下面的RecyclerView底部边缘(项目或扩展项目的某些部分对用户是不可见的),RecyclerView应向上滚动所有项目以显示我展开的整个项目.我尝试使用scrollToPosition和类似的方法滚动到扩展卡的结尾但没有成功.
所以,我的问题是如何在我扩展卡片向上滚动RecyclerView之后关于卡片的扩展部分的高度? - 这是我的想法,也许有人有更好的解决方案.
<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>
您可以按照自己开发的方式使用这个lib实例,试试这个:
第 1 步:将以下依赖项添加到您的build.gradle文件中:
**compile 'com.github.traex.expandablelayout:library:1.2.2'** use instead of
 compile 'com.github.traex.expandablelayout:library:1.3'
第 2 步:将以下视图添加到您的卡片布局中,card_layout必须如下所示:
<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"/>
第 3 步:在定义 RecyclerView 时,请记住:
recList.setItemViewCacheSize(ITEMS_COUNT);
欢迎询问:-)
| 归档时间: | 
 | 
| 查看次数: | 4832 次 | 
| 最近记录: |