Pau*_*nik 4 animation android view android-recyclerview
给出的是RecyclerView.在执行滑动时显示不同视图的最佳实践和最简单方法是什么?
这是一个类似的问题.但是使用该解决方案只能显示一个Bitmap.
随着recyclerview出现了令人敬畏的ItemTouchHelper,它有回调:
public void onChildDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {...}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我可以以某种方式利用此回调在两个视图之间滑动,如果是,则如何.
谢谢.
我正在处理类似的任务 - 需要在物品被擦掉时显示隐藏的底层面板.我已经设法在项目行视图的根RelativeLayout中有两个内部布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/actionsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hidden stuff is here"/>
</RelativeLayout>
<RelativeLayout android:id="@+id/itemLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@color/submission_row_bg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Swiping stuff is here"/>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在你的ItemViewHolder类中,我有相应的字段:
public class ItemViewHolder extends RecyclerView.ViewHolder {
RelativeLayout itemLayout;
RelativeLayout actionsLayout;
}
Run Code Online (Sandbox Code Playgroud)
然后在ItemTouchHelper.Callback中,我重写onChildDraw方法,如下所示:
public static class MyItemTouchCallback extends ItemTouchHelper.Callback {
public void onChildDraw(Canvas c, RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, float dX, float dY,
int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
//HERE IS THE TRICK
((ItemViewHolder) viewHolder).itemLayout.setTranslationX(dX);
} else {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
actionState, isCurrentlyActive);
}
}
}
Run Code Online (Sandbox Code Playgroud)
它有助于刷掉一个视图并显示底层视图.
| 归档时间: |
|
| 查看次数: |
1688 次 |
| 最近记录: |