Recyclerview快速滚动项消​​失 [英] Recyclerview fast scroll items disappear

查看:227
本文介绍了Recyclerview快速滚动项消​​失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我快速向下滚动四个可见网格项(右下)中的一项,将其进一步向下移动,

I am using GridLayoutManager with recyclerview, when i fast scroll down one item out of four visible grid items (bottom right ) is moved further down,

我正在使用本教程来实现快速滚动和快速滚动指示器此处

I am using this tutorial to implement fast scroll and fast scroll indicator here

推荐答案

猜我已经找到解决方案了.

Guess i've found the solution.

看起来像将回收视图再次附加到窗口时,它们的状态已更改为不可见"(为什么使用IDK).我们要做的就是再次使其可见.

Looks like when the Recycled Views are attached to the Window again, their state is changed to Invisible (IDK why). All we have to do is make it visible again.

幸运的是,RecyclerView.Adapter类具有一种方法,可以在将视图附加或重新附加到RecyclerView时进行处理.

Fortunately, RecyclerView.Adapter class has a method to handle when a view is attached or reattached to the RecyclerView.

    @Override
    public void onViewAttachedToWindow(ViewHolder holder){
        super.onViewAttachedToWindow(holder);
        if(!holder.tv_1.getText().toString().contentEquals("#EMPTYVIEW"))
            holder.root.setVisibility(View.VISIBLE);

        Log.i("ATTACHED_VISIBILITY",holder.tv_1.getText().toString()+"\t"+holder.root.getVisibility());
    }

我的ViewHolder类

My ViewHolder class

class ViewHolder extends RecyclerView.ViewHolder{
    TextView tv_1;
    TextView tv_2;
    ImageView iv;
    ImageButton bt;

    View root;

    ViewHolder(View v){
        super(v);

        //setIsRecyclable(false);     //to prevent views from getting deleted. :-(

        tv_1=(TextView)v.findViewById(R.id.aral_tv_title);
        tv_2=(TextView)v.findViewById(R.id.aral_tv_stitle);
        iv=(ImageView)v.findViewById(R.id.aral_iv);
        bt=(ImageButton)v.findViewById(R.id.aral_bt_more);

        tv_1.setTypeface(WorkActivity.mainTF);
        tv_2.setTypeface(WorkActivity.mainTF);

        root=v;
    }
}

希望这对您有所帮助.

这篇关于Recyclerview快速滚动项消​​失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆