Android属性动画之ObjectAnimator
相信对于Android初学者,对于Android中的动画效果一定很感兴趣,今天为大家总结一下刚刚学到的属性动画案例。
首先和一般的Android应用一样,我们先建一个工程,为了方便,我们的布局文件中就只添加一个ImageView和button按钮,代码如下:
<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/ic_launcher"
android:onClick="imgClick"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="动画"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="86dp"
android:onClick="buttonClick"/>
</RelativeLayout>
下面是我们action,为了便于大家学习,我将代码分享如下:
public class MainActivity extends Activity {
public ImageView imageView;
public Button button;
static int x = 0, xx = 0, y = 0, yy = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageView);
button = (Button)findViewById(R.id.button);
}
public void imgClick(View view){
Toast.makeText(this, "ImageView", Toast.LENGTH_SHORT).show();
}
public void buttonClick(View view){
// xx += 20;
// TranslateAnimation ta = new TranslateAnimation(x, xx, y, yy);//设置动画的偏移位移
// x += 20;
// ta.setDuration(1000);//设置动画的时长
// ta.setFillAfter(true);//设置动画结束后停留在该位置
// imageView.startAnimation(ta);
//属性动画调用start()方法后是一个异步操作
// ObjectAnimator.ofFloat(imageView, "translationX", 0F, 360F).setDuration(1000).start();//X轴平移旋转
// ObjectAnimator.ofFloat(imageView, "translationY", 0F, 360F).setDuration(1000).start();//Y轴平移旋转
// ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F).setDuration(1000).start();//360度旋转
//同步动画设计
// PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("translationX", 0, 360F);
// PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationY", 0, 360F);
// PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("rotation", 0, 360F);
// ObjectAnimator.ofPropertyValuesHolder(imageView, p1, p2 ,p3).setDuration(1000).start();
//通过AnimatiorSet来设计同步执行的多个属性动画
ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView, "translationX", 0F, 360F);//X轴平移旋转
ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView, "translationY", 0F, 360F);//Y轴平移旋转
ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F);//360度旋转
AnimatorSet set = new AnimatorSet();
//set.playSequentially(animator1, animator2, animator3);//分步执行
//set.playTogether(animator1, animator2, animator3);//同步执行
//属性动画的执行顺序控制
// 先同步执行动画animator2和animator3,然后再执行animator1
set.play(animator3).with(animator1);
set.play(animator2).after(animator3);
set.setDuration(1000);
set.start();
}
}
对于关键位置,我已经进行了详细的注释,大家可以拷贝到自己的项目中进行测试,相信大家一定可以掌握Android中的属性动画的知识。
Android属性动画之ObjectAnimator的更多相关文章
- 【转】android 属性动画之 ObjectAnimator
原文网址:http://blog.csdn.net/feiduclear_up/article/details/39255083 前面一篇博客讲解了 android 简单动画之 animtion,这里 ...
- Android 属性动画框架 ObjectAnimator、ValueAnimator ,这一篇就够了
前言 我们都知道 Android 自带了 Roate Scale Translate Alpha 多种框架动画,我们可以通过她们实现丰富的动画效果,但是这些宽家动画却有一个致命的弱点,它们只是改变了 ...
- Android属性动画之ObjectAnimator控制
Android为我们提供了大量的动画效果,如何通过这些动画来达到我们需要的效果呢?今天就为大家总结一下ObjectAnimator动画控制事件. 该项目的的布局文件只有两个控件:ImageView和B ...
- 详解Android属性动画
前面我们讲到的属性动画都是使用代码的定义方式:Android属性动画之ValueAnimator和Android属性动画之ObjectAnimator和AnimatorSet,下面我们再来看看使用XM ...
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...
- Android属性动画ObjectAnimator的使用1
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/106 属性动画ObjectAnimator的使用 属性动画 ...
- Android 属性动画ObjectAnimator和ValueAnimator讲解
区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view ,view自己做改变. ...
- Android属性动画
这几天看郭神的博客 Android属性动画完全解析(上),初识属性动画的基本用法之后,我自己突然想实现一种动画功能,就是我们在携程网.阿里旅行等等手机APP端买火车票的时候,看到有选择城市,那么就有出 ...
- Android属性动画完全解析(下)
转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...
随机推荐
- bfc+css
CSS BFC的定义 是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用.在创建了 Block Formatting Context 的元素 ...
- HDU 2068 RPG的错排
要求答对一半或以上就算过关,请问有多少组答案能使他顺利过关. 逆向思维,求答错一半或以下的组数 1,错排 错排公式的由来 pala提出的问题: 十本不同的书放在书架上.现重新摆放,使每本书都不在原来放 ...
- proxyd.c
/**************************************************************************** * program: proxyd * mo ...
- install openvpn and openvpn manager in ubuntu
sudo apt-get install openvpn sudo apt-get install network-manager-openvpn
- windows编程:资源和播放声音
要播放声音,要附加项:winmm.lib,然后包含头文件:#include <mmsystem.h> 播放声音用PlaySound函数,只能播放midi和wav波形文件. #define ...
- 安卓Notification的setLatestEventInfo is undefined出错不存在的解决
用最新版的SDK,在做状态栏通知时,使用了Notification的setLatestEventInfo(),结果提示: The method setLatestEventInfo(Context, ...
- (转载)JAVA线程池管理
平时的开发中线程是个少不了的东西,比如tomcat里的servlet就是线程,没有线程我们如何提供多用户访问呢?不过很多刚开始接触线程的开发攻城师却在这个上面吃了不少苦头.怎么做一套简便的线程开发模式 ...
- .net笔记
一.垃圾回收 1.运行.NET应用程序时,程序创建出来的对象都会被CLR跟踪, 2.哪些对象还会被用到(存在引用关系):哪些对象不会再被用到(不存在引用关系),CLR都是有记录的. 3.CLR会整理不 ...
- 我的ORM之示例项目
我的ORM索引 示例项目 code.taobao.org/svn/MyMvcApp/ 1. 编译 MyTool ,DbEnt, WebApp, 安装JRE. 2. 配置 Web.config 数据库字 ...
- 【腾讯Bugly干货分享】React移动web极致优化
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579083d1c9da73584b02587d 最近一个季度,我们都在为手Q家校 ...