RecyclerView條目item點選事件---放大
阿新 • • 發佈:2018-11-19
Adapter–建立介面
//建立介面
public interface RecyInterface{
void vh(Viewholder viewholder);
}
//宣告介面名
private RecyInterface mRecyInterface;
//暴露方法
public void setRecyInterface (RecyInterface recyInterface){
mRecyInterface=recyInterface;
}
在onBind裡寫
holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mRecyInterface.vh(holder); } });
Activity—放大動畫
介面卡呼叫介面
myRecyAdapter.setRecyInterface(new MyRecyAdapter.RecyInterface() { @Override public void vh(MyRecyAdapter.Viewholder viewholder) { AnimatorSet animatorSet = new AnimatorSet(); ObjectAnimator scaleX = ObjectAnimator.ofFloat(viewholder.itemView, "scaleX", new float[]{1f, 1.2f, 1f}); ObjectAnimator scaleY = ObjectAnimator.ofFloat(viewholder.itemView, "scaleY", new float[]{1f, 1.2f, 1f}); scaleX.setDuration(500); scaleY.setDuration(500); animatorSet.playTogether(scaleX,scaleY); animatorSet.start(); } });