加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 08:49:55 所属栏目:百科 来源:网络整理
导读:布局问价只有一张图片,略去 Activity package com.example.seven; import android.animation.Animator; import android.animation.AnimatorInflater; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.anno

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

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 {

private ImageView iv_zhangxin;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    iv_zhangxin = (ImageView) findViewById(R.id.iv_zhangxin);
    MyClick mc = new MyClick();
    iv_zhangxin.setOnClickListener(mc);
}

private class MyClick implements OnClickListener {
    @Override
    public void onClick(View v) {
        //AnimatorInflater:动画加载器,功能类似布局加载器
 Animator animator= AnimatorInflater.loadAnimator(MainActivity.this,R.animator.object_animator_animator_scale_x);
  animator.setDuration(5000);
  animator.setTarget(iv_zhangxin);
  animator.start();
    }

}

}

动画xml文件

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

<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" >

    <ImageView  android:id="@+id/iv_zhangxin" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/ic_launcher" />

</LinearLayout>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读