<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/cross_img" android:background="@mipmap/ic_launcher_round" android:layout_width="@dimen/x35" android:layout_height="@dimen/x35" /> <TextView android:id="@+id/cross_tv" android:textSize="@dimen/x13" android:layout_marginLeft="@dimen/x40" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:layout_alignParentRight="true" android:layout_margin="@dimen/x10" android:id="@+id/jia" android:layout_width="@dimen/x25" android:layout_height="@dimen/x25" android:src="@drawable/jia" /> <ImageView android:layout_width="@dimen/x25" android:visibility="gone" android:layout_height="@dimen/x25" android:layout_alignParentRight="true" android:layout_margin="@dimen/x10" android:id="@+id/jian" android:src="@drawable/jian"/> <ImageView android:layout_alignParentRight="true" android:layout_margin="@dimen/x10" android:layout_width="@dimen/x25" android:id="@+id/xinxi" android:visibility="gone" android:layout_height="@dimen/x25" android:src="@drawable/xinxi"/> <ImageView android:layout_alignParentRight="true" android:layout_margin="@dimen/x10" android:layout_width="@dimen/x25" android:visibility="gone" android:id="@+id/fenxiang" android:layout_height="@dimen/x25" android:src="@drawable/fenxiang"/> <ImageView android:layout_alignParentRight="true" android:layout_margin="@dimen/x10" android:visibility="gone" android:layout_width="@dimen/x25" android:id="@+id/aixin" android:layout_height="@dimen/x25" android:src="@drawable/aixin"/> </RelativeLayout> <TextView android:id="@+id/cross_time" android:textSize="@dimen/x13" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/cross_daimg" android:layout_width="match_parent" android:layout_height="@dimen/x150" android:layout_alignParentTop="true" android:layout_marginTop="4dp" android:layout_toEndOf="@+id/cross_tv" android:layout_toRightOf="@+id/cross_tv" android:scaleType="fitXY" /> </LinearLayout>
//点击事件在Recyclew中
package com.example.six.adapter; import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.six.R; import com.example.six.bean.CrossBean; import java.util.List; /** * Created by */ public class CrossAdapter extends RecyclerView.Adapter<CrossAdapter.ViewHolder>{ private Context context; private List<CrossBean.DataBean> list; public CrossAdapter(Context context, List<CrossBean.DataBean> list) { this.context = context; this.list = list; } class ViewHolder extends RecyclerView.ViewHolder{ private final ImageView img1; private final TextView tv1; private final TextView time; private final ImageView jia; private final ImageView jian; private final ImageView aixin; private final ImageView xinxi; private final ImageView fenxiang; public ViewHolder(View itemView) { super(itemView); img1=(ImageView)itemView.findViewById(R.id.cross_daimg); tv1 =(TextView)itemView.findViewById(R.id.cross_tv); time =(TextView)itemView.findViewById(R.id.cross_time); jia =(ImageView)itemView.findViewById(R.id.jia); jian =(ImageView)itemView.findViewById(R.id.jian); aixin =(ImageView)itemView.findViewById(R.id.aixin); xinxi =(ImageView)itemView.findViewById(R.id.xinxi); fenxiang =(ImageView)itemView.findViewById(R.id.fenxiang); } } @Override public CrossAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.ccross_recycle, null); ViewHolder holder = new ViewHolder(view); return holder; } @Override public void onBindViewHolder(final CrossAdapter.ViewHolder holder, int position) { Glide.with(context).load(list.get(position).getImgUrls()).into(holder.img1); holder.tv1.setText(list.get(position).getUser().getNickname()); holder.time.setText(list.get(position).getCreateTime()); //点击隐藏或者显示 holder.jia.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.jia.setVisibility(View.GONE); holder.jian.setVisibility(View.VISIBLE); holder.xinxi.setVisibility(View.VISIBLE); holder.aixin.setVisibility(View.VISIBLE); holder.fenxiang.setVisibility(View.VISIBLE); Animator animator = ObjectAnimator.ofFloat( holder.jian, "rotation", 360, 0 ); //平移 Animator animatr011 = ObjectAnimator.ofFloat( holder.xinxi, "rotation", 180, 0 ); Animator animatr012 = ObjectAnimator.ofFloat( holder.xinxi, "translationX", 0,-70 ); Animator animatr013 = ObjectAnimator.ofFloat( holder.xinxi, "alpha", 0, 1 ); Animator animatr021 = ObjectAnimator.ofFloat( holder.aixin, "rotation", 180, 0 ); Animator animatr022 = ObjectAnimator.ofFloat( holder.aixin, "translationX", 0,-140 ); //透明 Animator animatr023 = ObjectAnimator.ofFloat( holder.aixin, "alpha", 0, 1 ); Animator animatr031 = ObjectAnimator.ofFloat( holder.fenxiang, "rotation", 180, 0 ); Animator animatr032 = ObjectAnimator.ofFloat( holder.fenxiang, "translationX", 0, -210 ); //透明 Animator animatr033 = ObjectAnimator.ofFloat( holder.fenxiang, "alpha", 0, 1 ); AnimatorSet set = new AnimatorSet(); set.setDuration(500); set.play(animator) .with(animatr011) .with(animatr012) .with(animatr013) .with(animatr021) .with(animatr022) .with(animatr023) .with(animatr031) .with(animatr032) .with(animatr033); set.start(); } }); holder.jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.jia.setVisibility(View.VISIBLE); holder.jian.setVisibility(View.GONE); Animator animatr1 = ObjectAnimator.ofFloat( holder.jia, "rotation", 0,360 ); //平移 Animator animatr011 = ObjectAnimator.ofFloat( holder.xinxi, "rotation", 0,180 ); Animator animatr012 = ObjectAnimator.ofFloat( holder.xinxi, "translationX", -70,0 ); //透明 Animator animatr013 = ObjectAnimator.ofFloat( holder.xinxi, "alpha", 1, 0 ); Animator animatr021 = ObjectAnimator.ofFloat( holder.aixin, "rotation", 0,180 ); Animator animatr022 = ObjectAnimator.ofFloat( holder.aixin, "translationX", -140,0 ); //透明 Animator animatr023 = ObjectAnimator.ofFloat( holder.aixin, "alpha", 1, 0 ); Animator animatr031 = ObjectAnimator.ofFloat( holder.fenxiang, "rotation", 0,180 ); Animator animatr032 = ObjectAnimator.ofFloat( holder.fenxiang, "translationX", -210, 0 ); //透明 Animator animatr033 = ObjectAnimator.ofFloat( holder.fenxiang, "alpha", 1, 0 ); AnimatorSet set = new AnimatorSet(); set.setDuration(500); set.play(animatr1) .with(animatr011) .with(animatr012) .with(animatr013) .with(animatr021) .with(animatr022) .with(animatr023) .with(animatr031) .with(animatr032) .with(animatr033); set.start(); } }); } @Override public int getItemCount() { // return list.size(); } }