我用 RecyclerView 制作了一个小项目,里面有 CardView 项目。我创建了可扩展卡(通过按卡内的小按钮进行扩展)。
每张卡片始终包含可见部分(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>
您使用什么技术来做到这一点?
我遇到了同样的情况,但对我来说问题是这些功能ExpandAndCollapseViewUtil.expand() and ExpandAndCollapseViewUtil.collapse()从本教程Android 开发:Tarjetas 与 CardView所以我没有使用它。相反,我只是显示/隐藏卡片视图的视图,没有任何动画。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)