相信对于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的更多相关文章

  1. 【转】android 属性动画之 ObjectAnimator

    原文网址:http://blog.csdn.net/feiduclear_up/article/details/39255083 前面一篇博客讲解了 android 简单动画之 animtion,这里 ...

  2. Android 属性动画框架 ObjectAnimator、ValueAnimator ,这一篇就够了

    前言 我们都知道 Android 自带了 Roate Scale Translate Alpha 多种框架动画,我们可以通过她们实现丰富的动画效果,但是这些宽家动画却有一个致命的弱点,它们只是改变了 ...

  3. Android属性动画之ObjectAnimator控制

    Android为我们提供了大量的动画效果,如何通过这些动画来达到我们需要的效果呢?今天就为大家总结一下ObjectAnimator动画控制事件. 该项目的的布局文件只有两个控件:ImageView和B ...

  4. 详解Android属性动画

    前面我们讲到的属性动画都是使用代码的定义方式:Android属性动画之ValueAnimator和Android属性动画之ObjectAnimator和AnimatorSet,下面我们再来看看使用XM ...

  5. Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...

  6. Android属性动画ObjectAnimator的使用1

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/106 属性动画ObjectAnimator的使用 属性动画 ...

  7. Android 属性动画ObjectAnimator和ValueAnimator讲解

    区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view  ,view自己做改变. ...

  8. Android属性动画

    这几天看郭神的博客 Android属性动画完全解析(上),初识属性动画的基本用法之后,我自己突然想实现一种动画功能,就是我们在携程网.阿里旅行等等手机APP端买火车票的时候,看到有选择城市,那么就有出 ...

  9. Android属性动画完全解析(下)

    转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...

随机推荐

  1. modal的使用

    $modal是一个可以迅速创建模态窗口的服务,创建部分页,控制器,并关联他们 $modal仅有一个方法open(options) templateUrl:模态窗口的地址 template:用于显示ht ...

  2. [POI2008]KLO && POC

    题意:给定一个序列 s1, s2,...sn,以及一个k,求一个连续的k个数,把s[i]...s[i+k-1]变成一个数s',使得sigma(|s[j]-s'|)(i<=j<=i+k-1) ...

  3. Oracle第三方ado.net数据提供程序

    原文地址:http://www.infoq.com/cn/news/2009/06/oracleclient_deprecated 这项决定有部分原因是基于目前Oracle的第三方ADO.NET数据提 ...

  4. jquery ajax post 中文乱码解决

    jquery ajax post 方式默认传递的是UFT-8字符,即使页面设置了gbk编码也无效.字符传到后台时如果后台设置的gbk或者其他编码,就会出现乱码.解决很容易,将后台页面设置成UTF-8编 ...

  5. dp跟px的互相转换

    一 获取手机屏幕的密度 1 获取屏幕的宽和高,然后根据 直角三角形的 a边的平方+b边的平方=c边的平方 得到另一条边的长:然后除以 ,屏幕的尺寸,就是 手机的密度destity 2 根据上下文获取c ...

  6. 如何编写 Cloud9 JavaScript IDE 的功能扩展

    上周末我们在JSConf.eu发布了 Cloud9 IDE ,同时发布了对应的GitHub项目.在4天时间里该项目得到340个人的关注和将近50个fork.Cloud9的口号是由"由Java ...

  7. .Net平台下,分布式文件存储的实现

    遇到的问题 对于Web程序,使用一台服务器的时候,客户端上传的文件一般也都是存储在这台服务器上.但在集群环境中就行不通了,如果每个服务器都存储自己接受到的文件,就乱套了,数据库中明明有这个附件的记录, ...

  8. Xamarin.Android中使用ResideMenu实现侧滑菜单

    上次使用Xamarin.Android实现了一个比较常用的功能PullToRefresh,详情见:Xamarin. Android实现下拉刷新功能 这次将实现另外一个手机App中比较常用的功能:侧滑菜 ...

  9. C++ REST SDK的基本用法

    微软开发了一个开源跨平台的http库--C++ REST SDK(http://casablanca.codeplex.com/),又名卡萨布兰卡Casablanca,有个电影也叫这个名字,也许这个库 ...

  10. [.NET领域驱动设计实战系列]专题十一:.NET 领域驱动设计实战系列总结

    一.引用 其实在去年本人已经看过很多关于领域驱动设计的书籍了,包括Microsoft .NET企业级应用框架设计.领域驱动设计C# 2008实现.领域驱动设计:软件核心复杂性应对之道.实现领域驱动设计 ...