Similar Facebook reactions - Animated view with ObjectAnimator clicklistener not working

帅比萌擦擦* 提交于 2019-12-06 01:34:44

You can't do this, because this is not the way Android touch event process works.

ViewGroup or it's subclass(FrameLayout, RelativeLayout, LinearLayout, etc) dispatch touch event to it's childviews based on childview's frame.so when you click on iv2 or iv3 or iv4, the touch event didn't even passed to the parent(RecyclerView's item),so the parent view never had a change to handle or dispatch the touch event to iv2 or iv3 or iv4.

what you should do is pop a new Window with iv1-iv4 in it using WindowManager, and carefully calculate the position so that it will look just like the way you did to the RecyclerView's item.only then you can receive the touchevent and onClick event

Facebook Reactions is definitely using WindowManager to pop a new Window with buttons:

here's what it looks like when I turn on the Profile GPU rendering option in Developer options




notice there are two rows of bars on screen now when I long click the like button,the smaller one is a new window which contains reactions buttons

The clicklistener is just in the wrong position, it should be in the viewholder

// Adapter

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
    return NewsViewHolder.newInstance(parent);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    final NewsEntry newsEntity = news.get(position);
    ((NewsViewHolder) holder).bind(newsEntity);
}

// ViewHolder
public NewsViewHolder(NewsViewHolderBinding binding) {
    super(binding.getRoot());
    itemView.findViewById(R.id.viewname).setOnClickListener(this);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!