使用信标检测更改recyclerview项的Alpha

使用信标检测更改recyclerview项的Alpha

本文介绍了使用信标检测更改recyclerview项的Alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Fragment中,我有一个使用RecyclerView构造的项目列表(适配器和视图保持器).列表的每个项目都与一个估计信标链接.所以我想在检测到信标时突出显示项目视图(setAlpha或添加imageView).

In a Fragment I have a list of items construct with RecyclerView (adapter and viewholder).Each item of the list is linked with a estimote beacon.So i want to highlight the item view (setAlpha or add a imageView) when the beacon is detected.

信标检测在片段文件中:

The beacon detection is in the fragment file :

beaconManager.setRangingListener(new BeaconManager.RangingListener() {
            @Override
            public void onBeaconsDiscovered(Region region, List<Beacon> list) {
                if (!list.isEmpty()) {
                    Beacon nearestBeacon = list.get(0);
                    replaceIconBeaconCard(nearestBeacon);
                    Log.d("Airport", "Nearest places: " + nearestBeacon);
                }
            }
        });

实际上,我在项目视图上显示一个信标图标.但目的是突出显示检测到的项目,并在其他项目上添加一个字母.

Actually, I display a beacon icon on the item view. But the purpose is to highlight the detected item and put a alpha on the others items.

private void replaceIconBeaconCard(Beacon beacon){
        for(SItem item: items) {
            if (!item.getMajor().equals("")) {
                int i = item.getId().intValue();
                SCard card = listCards.get(i-1);
                if (Integer.parseInt(item.getMajor()) == beacon.getMajor()) {
                    rv.getLayoutManager().scrollToPosition(i);
                    int resID = getResources().getIdentifier("beacon_ice", "drawable", getActivity().getPackageName());
                    card.setField_1(resID);
                } else {
                    card.setField_1(Color.TRANSPARENT);
                }
            }
        }
        mAdapter.notifyDataSetChanged();
    }

我不知道如何访问项目布局并更改Alpha.

I don't know how I can access to item layout and change the alpha.

推荐答案

最后,我在adapater中使用对象SCard访问布局Alpha:

Finally i access to the layout alpha with the object SCard in the adapater :

在活动中,我设置了字母

In the activity i set the alpha

card.setField_2(0.5F);

在查看器中,我添加了设置器

In the viewholder i add the setter

 public void setItemCardField2(float alpha) {
        swipeLayout.setAlpha(alpha);
    }

然后由适配器来完成工作

And the adapter make the job

final ShowroomCard card = mItemList.get(position);
viewHolder.setItemCardField2(card.getField_2());

这篇关于使用信标检测更改recyclerview项的Alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:27