import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationSet;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import java.util.jar.Pack200;
public class BaseAda extends BaseAdapter {
private List<Bean> list;
private Context context;
public BaseAda(List<Bean> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
View view1 = LayoutInflater.from(context).inflate(R.layout.item, null);
TextView tit= view1.findViewById(R.id.tit);
final ImageView jia = view1.findViewById(R.id.jia);
TextView tv_tit = view1.findViewById(R.id.tv_tit);
final ImageView copylink1 = view1.findViewById(R.id.copylink1);
final ImageView report1 = view1.findViewById(R.id.report1);
final ImageView shiled1 = view1.findViewById(R.id.shiled1);
tit.setText(list.get(i).getTitle());
tv_tit.setText(list.get(i).getContext());
//动画设置
jia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!b)
{
jia(report1,2);
jia(copylink1,3);
jia(shiled1,4);
jia.setImageResource(R.mipmap.icon_packup);
b=true;
}
else
{
jia2(report1,2);
jia2(copylink1,3);
jia2(shiled1,4);
jia.setImageResource(R.mipmap.icon_open);
b=false;
}
}
});
return view1;
}
private boolean b=false;
private void jia(View view,int b) {
int width = ((Activity) context).getWindowManager().getDefaultDisplay().getWidth();
ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(view,"X",width-view.getWidth(),width-view.getWidth()*b);
ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(view,"rotation",360,0);
AnimatorSet set=new AnimatorSet();
set.play(objectAnimator).with(objectAnimator1);
set.setDuration(2000);
set.start();
}
private void jia2(View view,int b) {
int width = ((Activity) context).getWindowManager().getDefaultDisplay().getWidth();
ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(view,"X",width-view.getWidth()*b,width-view.getWidth());
ObjectAnimator objectAnimator1=ObjectAnimator.ofFloat(view,"rotation",0,360);
AnimatorSet set=new AnimatorSet();
set.play(objectAnimator).with(objectAnimator1);
set.setDuration(2000);
set.start();
}
}
布局:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dip">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:id="@+id/tit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="60dip"
android:text="标题"
/>
<ImageView
android:id="@+id/shiled1"
android:layout_width="30dip"
android:layout_centerVertical="true"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:src="@mipmap/shiled1"
/>
<ImageView
android:id="@+id/report1"
android:layout_width="30dip"
android:layout_centerVertical="true"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:src="@mipmap/report1"
/>
<ImageView
android:id="@+id/copylink1"
android:layout_width="30dip"
android:layout_centerVertical="true"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:src="@mipmap/copylink1"
/>
<ImageView
android:id="@+id/jia"
android:layout_width="30dip"
android:layout_centerVertical="true"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:src="@mipmap/icon_open"
/>
</RelativeLayout>