如何用Blurry模糊ListView项目?

时间:2017-10-17 15:09:26

标签: android listview blur blurry

我想模糊ListView项目。我在CustomListViewAdapter的getView()中模糊(使用Blurry库):

@Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final AirdropResult airdrop = getItem(position);
        boolean bWasNull = false;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.result_item, parent, false);
            bWasNull = true;
        }

        final RelativeLayout airdropListRowInside = (RelativeLayout) convertView.findViewById(R.id.airdropListRowInside);

        final TextView tvName = (TextView) airdropListRowInside.findViewById(R.id.tvCoinName);
        final TextView tvDesc = (TextView) airdropListRowInside.findViewById(R.id.tvDesc);
        final TextView tvStartdate = (TextView) airdropListRowInside.findViewById(R.id.tvStartdate);

        tvName.setText(airdrop._name);
        tvDesc.setText(airdrop._shortdesc);

        if(bWasNull) {
            convertView.post(new Runnable() {
                @Override
                public void run() {
                    Blurry.with(getContext())
                            .radius(5)
                            .sampling(2)
                            .async()
                            .animate(100)
                            .onto(airdropListRowInside);
                }
            });
        }

        return convertView;
    }

enter image description here

似乎布局变得模糊但是它在顶部呈现非模糊布局(只有一个布局)。我使用了Runnable because it is apparently needed

我假设这是因为ListView如何重用项目,但没有足够的理解来解决它。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这是因为bWasNull是在getView()内定义的。所以当false再次被调用时,它总是被重置为getView(),这次convertView而不是null所以bWasNull不是真的,而且模糊是未申请新convertView

bWasNull之外定义getView()。 B.T.W我没有看到使用这个bWasNull