Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “加快回收商查看速度”;“刷卡”;动画_Android - Fatal编程技术网

Android “加快回收商查看速度”;“刷卡”;动画

Android “加快回收商查看速度”;“刷卡”;动画,android,Android,我在我的RecyclerView中添加了一个自定义的ItemTouchHelper.SimpleCallback类,以添加“刷卡时解除”功能,其中用户可以向左刷卡一个项目,并从列表中删除该项目 通过将dX(来自onchildraw())除以10,我将视图可以向左“滑动”的量限制为视图长度的10%。但是,用户必须刷卡的长度为屏幕的100%,才能刷卡10%。我想限制刷卡(增加物品刷卡速度?),这样用户只需刷卡屏幕的10%就可以让物品刷卡10%。见下图: 紫色圆圈是用户触摸。当用户滑动所有屏幕宽度时

我在我的
RecyclerView
中添加了一个自定义的
ItemTouchHelper.SimpleCallback
类,以添加“刷卡时解除”功能,其中用户可以向左刷卡一个项目,并从列表中删除该项目

通过将dX(来自onchildraw())除以10,我将视图可以向左“滑动”的量限制为视图长度的10%。但是,用户必须刷卡的长度为屏幕的100%,才能刷卡10%。我想限制刷卡(增加物品刷卡速度?),这样用户只需刷卡屏幕的10%就可以让物品刷卡10%。见下图:

紫色圆圈是用户触摸。当用户滑动所有屏幕宽度时,项目滑动10%(红色是滑动时显示“后面”项目的布局)

我怎样才能提高擦拭速度,以刷10%的屏幕宽度就足够了,还是刷整个屏幕宽度

以下是我的ItemTouchHelper.SimpleCallback类的代码:

public class SwipeDeleteHelper extends ItemTouchHelper.SimpleCallback {

    private GameAdapter adapter;
    private Drawable icon;
    private final ColorDrawable background;
    private static final int LIMIT_SWIPE_LENGTH = 10;


    public SwipeDeleteHelper(GameAdapter adapter, Context context) {
        super(0, ItemTouchHelper.LEFT);
        this.adapter = adapter;
        icon = ContextCompat.getDrawable(adapter.getContext(),
                R.drawable.delete);
        background = new ColorDrawable(context.getColor(R.color.colorAccent));
    }

    @Override
    public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
        int position = viewHolder.getAdapterPosition();
        adapter.deleteItem(position);
    }

    @Override
    public void onChildDraw(@NotNull Canvas c, @NotNull RecyclerView recyclerView, @NotNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
        dX = dX/LIMIT_SWIPE_LENGTH;

        super.onChildDraw(c, recyclerView, viewHolder, dX,
                dY, actionState, isCurrentlyActive);

        View itemView = viewHolder.itemView;
        int backgroundCornerOffset = 20;

        int iconMargin = (itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
        int iconTop = itemView.getTop() + (itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
        int iconBottom = iconTop + icon.getIntrinsicHeight();

        if(dX < 0) { //left swipe
            int iconLeft = itemView.getRight() - iconMargin - icon.getIntrinsicWidth();
            int iconRight = itemView.getRight() - iconMargin;
            icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);

            background.setBounds(itemView.getRight() + ((int) dX) - backgroundCornerOffset,
                    itemView.getTop(), itemView.getRight(), itemView.getBottom());
        } else { //unswiped
            background.setBounds(0, 0, 0, 0);
        }
        background.draw(c);
        icon.draw(c);
    }

}
公共类SwipeDeleteHelper扩展了ItemTouchHelper.SimpleCallback{
专用游戏适配器;
私人绘图图标;
私人最终彩色背景;
专用静态最终整数限制\u滑动\u长度=10;
公共SwipeDeleteHelper(游戏适配器、上下文){
超级(0,ItemTouchHelper.LEFT);
this.adapter=适配器;
icon=ContextCompat.getDrawable(adapter.getContext(),
R.可提取。删除);
background=新的ColorDrawable(context.getColor(R.color.colorAccent));
}
@凌驾
公共布尔onMove(@NonNull RecyclerView RecyclerView,@NonNull RecyclerView.ViewHolder ViewHolder,@NonNull RecyclerView.ViewHolder target){
返回false;
}
@凌驾
公共void onsweed(@NonNull RecyclerView.ViewHolder ViewHolder,int-direction){
int position=viewHolder.getAdapterPosition();
适配器。删除项目(位置);
}
@凌驾
public void onchildraw(@NotNull Canvas c、@NotNull recycleriew recycleriew、@NotNull recycleriew.ViewHolder ViewHolder、float dX、float dY、int actionState、boolean isCurrentlyActive){
dX=dX/限制刷卡长度;
super.onchildraw(c、recyclerView、viewHolder、dX、,
dY,actionState,当前处于活动状态);
View itemView=viewHolder.itemView;
int backgroundCornerOffset=20;
int iconMargin=(itemView.getHeight()-icon.getIntrinsicHeight())/2;
int iconTop=itemView.getTop()+(itemView.getHeight()-icon.getIntrinsicHeight())/2;
int iconBottom=iconTop+icon.getIntrinsicHeight();
如果(dX<0){//向左滑动
int iconLeft=itemView.getRight()-iconMargin-icon.getIntrinsicWidth();
int iconRight=itemView.getRight()-iconMargin;
icon.setBounds(iconLeft、iconTop、iconRight、iconBottom);
background.setBounds(itemView.getRight()+((int)dX)-backgroundCornerOffset,
itemView.getTop()、itemView.getRight()、itemView.getBottom());
}否则{//
背景.背景(0,0,0,0);
}
背景图(c);
图标绘制(c);
}
}

覆盖GetSwipThreshold以返回0.1f:

@Override
    public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) {
        return 0.1f;
    }

我发现将
getSwipeThreshold()
调整为
0.1f
是不够的。我还重写了公共浮点getSwipeVelocityThreshold(浮点默认值) 返回
1f.

根据文档(),值越低,滑动和删除就越困难,因为您必须以较少的对角线拖动更多的直线。我将该值
1f
0.5f
一起用于
getSwipeThreshold()
方法,以实现我自己“刷卡删除”的理想阈值。。我建议两者结合使用

谢谢你的回答!这几乎就是我需要的。这允许用户只需滑动10%即可调用onsweep()。但是,要使视图滑动10%,用户仍然需要滑动全屏宽度。有没有关于如何让视图也“加速”的建议?如果你不将dX除以10,用户就不必刷整个宽度,也许这就是你想要的行为?