Animator xml解析Animator 和第三种图片点击方式
来源:互联网 发布:嵌入式系统与人工智能 编辑:程序博客网 时间:2024/06/09 23:42
animator
直接用animator写动画
//scaleX scaleY alpha rotateX rotateY translationX translationY translationZ ObjectAnimator.ofFloat(mImageView,"scaleX",0.0f,1.0f).setDuration(3000).start();
xml 解析animator
要注意的是在Android studio和eclipse中创建时不一样:
Android studio中创建animation文件和animator时建在不同的文件中
而eclipse中只需要创建一个文件就行了,在它里面可以放animator和animation
先在res中创建一个animator文件、
在animator中写动画效果
?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator android:duration="1000" android:propertyName="scaleX" android:valueFrom="0.0" android:valueTo="1.0"></objectAnimator> <objectAnimator android:duration="1000" android:propertyName="scaleY" android:valueFrom="0.0" android:valueTo="1.0" android:startOffset="1000"></objectAnimator></set>
在主界面中调用xml中的文件
Animator animator=AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.animator); animator.setTarget(mImageView); animator.start();
第三种图片点击方式
就是在写ImageView时就写一个点击方法然后在主界面中调用
这样就点击图片就行了
<ImageView android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="wrap_content" //写一个点击方法 android:onClick="startAnimator" android:src="@mipmap/ic_launcher"/>
把写的点击方法在主界面中调用
public void startAnimator(View view){ //scaleX scaleY alpha rotateX rotateY translationX translationY translationZ //ObjectAnimator.ofFloat(mImageView,"scaleX",0.0f,1.0f).setDuration(3000).start(); Animator animator=AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.animator); animator.setTarget(mImageView); animator.start(); }
两种方法的整体代码
public class MainActivity extends AppCompatActivity { private Button mButton; private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageView= (ImageView) findViewById(R.id.imageview); mButton= (Button) findViewById(R.id.button); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {// AnimationSet set=new AnimationSet(false);// AlphaAnimation animation1=new AlphaAnimation(1.0f,0.0f);//透明动画// TranslateAnimation animation2=new TranslateAnimation(0,mImageView.getMeasuredWidth(),0,0);// RotateAnimation animation3=new RotateAnimation(0,-360,100,100);//默认中旋转点事0,0点,-180为逆时针旋转180度// ScaleAnimation animation4=new ScaleAnimation(1,1.5f,0.5f,1);// // 1开始时图片的X的大小的倍数,1.5f为把图片X的大小放大1.5倍后面两个参数为图片Y的大小// animation1.setDuration(5000);// animation2.setDuration(5000);// animation3.setDuration(5000);// animation4.setDuration(5000);// set.addAnimation(animation1);// set.addAnimation(animation2);// set.addAnimation(animation3);// set.addAnimation(animation4); //mImageView.setAnimation(animation); Animation animation= AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation_rotate); mImageView.startAnimation(animation); } }); } public void startAnimator(View view){ //scaleX scaleY alpha rotateX rotateY translationX translationY translationZ //ObjectAnimator.ofFloat(mImageView,"scaleX",0.0f,1.0f).setDuration(3000).start(); Animator animator=AnimatorInflater.loadAnimator(getApplicationContext(), R.animator.animator); animator.setTarget(mImageView); animator.start(); }}
0 0
- Animator xml解析Animator 和第三种图片点击方式
- animator
- Animator
- Animator
- Camtasis和Hippo Animator
- animation和animator
- View Animator(Tween Animator)、Drawable Animator(Frame Animator)、Property Animator
- 动态加载Animator和AnimatorController
- Object Animator和Tween Animation
- Animator引用其中参数和状态的两种方法
- unity animator的一种使用方式
- gif图片制作工具Ulead GIF Animator
- android animator
- Android_Loader/Animator
- Animator控制
- android animator
- Animator介绍
- Animator.speed
- springMVC教程初级(三)springmvc+Mybatis整合(重点 )
- 进程的三个状态的转换
- 程序调用plink.exe发送命令设置路由
- jQuery中bind,live,delegate与one方法的用法及区别
- viewpager + fragmentpageradapter 切换fragment产生的问题
- Animator xml解析Animator 和第三种图片点击方式
- 判断一个文本文件的编码格式
- c算法-小球落下反弹高度
- QT 读取txt 文件
- 进程与任务的区别
- 持续集成CI(三)待具体实践
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
- Java泛型
- MySQL联合查询