public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickXML(View v){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.alpha); //加载动画文件
view.clearAnimation(); //清一下之前的动画效果
view.startAnimation(animation); //开始一个新的动画
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickJava(View v){
Animation animation = new AlphaAnimation(0.1f,1.0f); //接受参数类型float,需要从double转型
animation.setDuration(2000);
animation.setRepeatCount(3);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickXML(View v){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.scale);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickJava(View v){
Animation animation =new ScaleAnimation(0.0f, 2.0f, 0.0f, 2.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setRepeatCount(3);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickXML(View v){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.trans);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickJava(View v){
Animation animation=new TranslateAnimation(1080.0f, 0f, 0f, 0f);
animation.setDuration(2000);
animation.setRepeatCount(3);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickXML(View v){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.rotate);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickJava(View v){
Animation animation=new RotateAnimation
(0.0f, 360.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setRepeatCount(3);
view.clearAnimation();
view.startAnimation(animation);
}
}
public class MainActivity extends Activity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, IControl { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main7); //1.拿到listview对象 ListView lv = (ListView) this.findViewById(R.id.lv_main); //2.数据源 List
//是否只播放一次 - //单帧
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickXML(View v){
view.setBackgroundResource(R.drawable.frame); //加载逐帧动画xml文件放到view背景里
AnimationDrawable animationDrawable=(AnimationDrawable)view.getBackground(); //再从背景里反向拿出AnimationDrawable
animationDrawable.start(); //启动
}
}
public class MainActivity4 extends AppCompatActivity { ImageView view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity1); view = (ImageView) findViewById(R.id.img); } public void btnClickJava(View v){ AnimationDrawable animationDrawable = new AnimationDrawable(); //帧动画对象 view.setBackgroundDrawable(animationDrawable); //设置组件背景 String packageName = this.getApplicationContext().getPackageName(); //获取当前包名 for(int i = 1; i <= 8; i++){ //从图片名称反射资源ID int id = this.getResources().getIdentifier("loading_"+i, "drawable", packageName); Drawable frame = this.getResources().getDrawable(id); //得到动画帧的对象 animationDrawable.addFrame(frame, 80); //添加帧,设定时间间隔 } animationDrawable.setOneShot(false);// 只运行一次,false-无限循环 animationDrawable.start();// 开始播放 } }
public class MainActivity4 extends AppCompatActivity {
ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity1);
view = (ImageView) findViewById(R.id.img);
}
public void btnClickJava(View v){
startFrameAnimation(this,"progress_",1,8,200,false);
}
public void startFrameAnimation(Context context, String prefix, int start, int end, int dur, boolean oneShot){
AnimationDrawable animationDrawable = new AnimationDrawable(); //帧动画对象
view.setBackgroundDrawable(animationDrawable); //设置组件背景
String packageName = context.getApplicationContext().getPackageName(); //获取当前包名
for(int i = start; i <= end; i++){
//从图片名称反射资源ID
int id = context.getResources().getIdentifier(prefix+i, "drawable", packageName);
Drawable frame = context.getResources().getDrawable(id); //得到动画帧的对象
animationDrawable.addFrame(frame, dur); //添加帧,设定时间间隔
}
animationDrawable.setOneShot(oneShot);// 只运行一次,false-无限循环
animationDrawable.start();// 开始播放
}
}