王学岗属性动画上(九)——使用xml文件配置动画(1)

前端之家收集整理的这篇文章主要介绍了王学岗属性动画上(九)——使用xml文件配置动画(1)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

布局问价只有一张图片,略去

Activity

package com.example.seven;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
@SuppressLint(“NewApi”)
public class MainActivity extends Activity {

  1. private ImageView iv_zhangxin;
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7. iv_zhangxin = (ImageView) findViewById(R.id.iv_zhangxin);
  8. MyClick mc = new MyClick();
  9. iv_zhangxin.setOnClickListener(mc);
  10. }
  11.  
  12. private class MyClick implements OnClickListener {
  13. @Override
  14. public void onClick(View v) {
  15. //AnimatorInflater:动画加载器,功能类似布局加载器
  16. Animator animator= AnimatorInflater.loadAnimator(MainActivity.this,R.animator.object_animator_animator_scale_x);
  17. animator.setDuration(5000);
  18. animator.setTarget(iv_zhangxin);
  19. animator.start();
  20. }
  21.  
  22. }

}

动画xml文件

文件目录为res/animator/动画xml文件

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" >
  2.  
  3. <ImageView android:id="@+id/iv_zhangxin" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/ic_launcher" />
  4.  
  5. </LinearLayout>

猜你在找的XML相关文章