package com.example.rk_02;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
/**
* A simple {@link Fragment} subclass.
*/
public class BlankFragment extends Fragment {
private View view;
private ImageView imageView;
private Button btn01, btn02,btn03,btn04;
private TranslateAnimation translateAnimation;
private RotateAnimation rotateAnimation;
private ScaleAnimation scaleAnimation;
private AlphaAnimation alphaAnimation;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_blank, container, false);
;
imageView = (ImageView) view.findViewById(R.id.iv);
btn01 = (Button) view.findViewById(R.id.btn01);
btn02 = (Button) view.findViewById(R.id.btn02);
btn03= (Button) view.findViewById(R.id.btn03);
btn04= (Button) view.findViewById(R.id.btn04);
//旋转
btn01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(2000);
rotateAnimation.setRepeatCount(1);
rotateAnimation.setRepeatMode(Animation.REVERSE);
rotateAnimation.setFillAfter(true);
imageView.startAnimation(rotateAnimation);
}
});
//透明
btn02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(2000);
alphaAnimation.setRepeatCount(1);
alphaAnimation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(alphaAnimation);
}
});
btn03.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 2
, Animation.RELATIVE_TO_SELF, -0.5f, Animation.RELATIVE_TO_SELF, 1.5f);
translateAnimation.setDuration(2000);
translateAnimation.setRepeatCount(1);
translateAnimation.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(translateAnimation);
}
});
//放大
btn04.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scaleAnimation = new ScaleAnimation(0.5f, 2, 0.1f, 3, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(2000);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setRepeatMode(Animation.ABSOLUTE);
scaleAnimation.setFillAfter(true);
imageView.setAnimation(scaleAnimation);
}
});
return view;
}
public void fly(View view) {
AnimationSet set = new AnimationSet(false);
set.addAnimation(translateAnimation);
set.addAnimation(alphaAnimation);
set.addAnimation(scaleAnimation);
set.addAnimation(rotateAnimation);
}
}
补间动画 旋转 平移 缩放 透明
最新推荐文章于 2021-05-26 15:26:14 发布