android动画-Property Animation

Property Animation 属性动画,这个是在Android 3.0中才引进的。

Property Animation其改变的是对象属性对应的值,应用于任何对象,而Tween Animation更改的是绘画的效果,其属性值是没有变化的。

ObjectAnimator:更改对象的属性值

使用方法:

ObjectAnimator translationRight = ObjectAnimator.ofFloat(m_tv, "X",width);

translationRight.setDuration(1500);

translationRight.start();

这是一个平移的效果,ObjectAnimator.ofFloat(m_tv, "X",width);第一个参数是:对象 第二个参数:该对象的属性,属性有必须有对应的getX()和setX()方法,第三个参数:一个可变参数的值

如果只写了一个值,那么就默认从当前的值变为填写的值,如果填写了多个,就按照填写的顺序做相应的变化,

setDuration():设置运行的时间,start():开启

AnimatorSet:将多个ObjectAnimator的效果一直执行或则按照先后顺序执行

ObjectAnimator translationRight = ObjectAnimator.ofFloat(m_tv, "X",width);

ObjectAnimator translationLeft = ObjectAnimator.ofFloat(m_tv, "X", 0f);

ObjectAnimator translationDown = ObjectAnimator.ofFloat(m_tv, "Y",height);

ObjectAnimator translationUp = ObjectAnimator.ofFloat(m_tv, "Y", 0);

AnimatorSet as = new AnimatorSet();

as.play(translationRight).before(translationLeft);

as.play(translationRight).with(translationDown);

as.play(translationLeft).with(translationUp);

paly() with()  before()  after() 设置执行的顺序 start()开启

下面代码的介绍请参考:  http://www.open-open.com/lib/view/open1329994048671.html

ValueAnimator,TypeEvalutors,TimeInterplator,Keyframes

部分示例代码:

<span style="font-family:SimSun;font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/girl" />

    <EditText
        android:id="@+id/edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp" />

</LinearLayout></span>

实现:

<span style="font-family:SimSun;font-size:18px;">private void initImageAnimationSet() {
		ImageView image = (ImageView) findViewById(R.id.image);
		ObjectAnimator obOutX = ObjectAnimator.ofFloat(image, "X", 200);
		ObjectAnimator obOutY = ObjectAnimator.ofFloat(image, "Y", 200);
		ObjectAnimator obInX = ObjectAnimator.ofFloat(image, "X", 0);
		ObjectAnimator obInY = ObjectAnimator.ofFloat(image, "Y", 0);
		final AnimatorSet set = new AnimatorSet();
		set.play(obOutX).with(obOutY);
		set.play(obInX).with(obInY);
		set.play(obOutX).before(obInX);
		image.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				set.start();

			}
		});
	}

	/**
	 * ObjectAnimator使用
	 */
	private void initEditObjectAnimator() {
		EditText edt = (EditText) findViewById(R.id.edit_text);
		final ObjectAnimator translationRight = ObjectAnimator.ofFloat(edt,
				"X", 0, 50, -10, 40, -5, 30, -3, 20, -1, 10, 0);
		translationRight.setDuration(1500);

		edt.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				if (TextUtils.isEmpty(s.toString())) {
					translationRight.start();
				}
			}
		});
	}</span>

案例代码下载:

效果图:

时间: 2024-08-29 13:28:51

android动画-Property Animation的相关文章

Android动画-Property Animation(一)

本章内容 在之前 <Android动画-概述>中,我大概说了下Android Property Animation的由来,这里就不做多介绍了,Property Animation 肯定不是一章就能讲的完的,接下来的几章都是建立在代码.效果图的基础上,介绍Property Animation的用法. 本章主要讲的是 ObjectAnimator ,包括代码生成动画,XML加载动画. 简述:在给出一大堆代码之前,先通过效果图来看看一些有趣的动画,通过一个简单有趣的动画逐步展开: 这绝对是一个非常有

Android属性动画Property Animation系列三之LayoutTransition(布局容器动画)

在上一篇中我们学习了属性动画的ObjectAnimator使用,不了解的可以看看 Android属性动画Property Animation系列一之ObjectAnimator.这一篇我们来学点新的东西.做项目的时候应该碰到这种问题:根据不同条件显示或者隐藏一个控件或者布局,我们能想到的第一个方法就是 调用View.setVisibility()方法.虽然实现了显示隐藏效果,但是总感觉这样的显示隐藏过程很僵硬,让人不是很舒服,那么有没有办法能让这种显示隐藏有个过渡的动画效果呢?答案是肯定的,不言

Android属性动画Property Animation系列一之ValueAnimator

Android动画分类 市面上的很多APP都用到动画效果,动画效果用的好可以提升用户的体验度.那么Android系统都有哪些机制的动画呢? 1.逐帧动画(frame-by-frame animation).逐帧动画的工作原理很简单,其实就是将一个完整的动画拆分成一张张单独的图片,然后再将它们连贯起来进行播放,类似于动画片的工作原理. 2.补间动画(tweened animation)则是可以对View进行一系列的动画操作,包括淡入淡出.缩放.平移.旋转四种. 3.属性动画Property Ani

Android 动画详解之属性动画(Property Animation)(下)

Hello,大家好,最近好长时间没有写博客了,因为我决定辞职了. 废话不多说,我们还是来看属性动画在上一篇Android 动画详解之属性动画(Property Animation)中我们简单的介绍了一下属性动画的用法,其实属性动画还有更多有趣的用法. 1,在xml中使用 在eclipse中我们右键新建xml可以选择新建属性动画,如图 我们选择objectAnimator,然后我们就会看到熟悉的一幕 然后我们用智能提示就可以看到更熟悉的 没错,这下我们应该知道怎么用xml布局来写属性动画了吧 <s

Android属性动画Property Animation系列一之ObjectAnimator

转载请注明出处 http://blog.csdn.net/feiduclear_up/article/details/45915377 前面一篇博客解读了Android属性动画Property Animation系列一之ValueAnimator的相关知识点以及怎么使用.这篇博客继续解读Android 属性动画 ObjectAnimator 类的使用. ObjectAnimator 相比ValueAnimator类,ObjectAnimator更加实用,因为它真正可以作用在一个对象上.不过Obj

属性动画-Property Animation之ViewPropertyAnimator 你应该知道的一切

转载请注明出处(万分感谢!): http://blog.csdn.net/javazejian/article/details/52381558 出自[zejian的博客] 关联文章: 走进绚烂多彩的属性动画-Property Animation(上篇) 走进绚烂多彩的属性动画-Property Animation之Interpolator和TypeEvaluator(下篇) ??原本打算这篇作为属性动画的完结篇,但目前情况来看,估计无法完结,前两天研究了一下ViewPropertyAnimat

(四)Android动画开发---Animation动画效果详解

Android 使用Animation的具体操作方法我们将会在这篇文章中做一个详细的介绍.大家可以通过这里举出的代码进行解读,并从中了解到相关操作技巧,方便我们将来开发应用,并且加深对这一操作系统的理解程度. 在Android中,分别可以在xml中定义Animation,也可以在程序代码中定义. 动画类型 Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转

android 动画属性Animation

Animation 在android 程序当中很多时候要用到动画效果,而动画效果主要是Animation来实现的,API给出的解释: 其中包含4种动画效果 AlphaAnimation 渐变透明度 RotateAnimation 画面旋转 ScaleAnimation 渐变尺寸缩放 TranslateAnimation 位置移动 但如果你想把这些动画效果联合起来就需要用到一个类AnimationSet  动画集. 下面就对这几个类进行一个简单的解释: AlphaAnimation 的例子: 1

Android学习之 属性动画&lt;Property Animation&gt;

property 动画系统是相当健壮的框架,它几乎可以动画显示任何对象. 你可以定义一个动画来定时改变任何对象的属性值,不论该对象是否在屏幕上显示. property 动画将以一定的时间间隔修改属性值(对象中的字段值). 要实现动画显示,你须指定对象的相应属性(比如对象的屏幕位置),以及动画时长.动画时间间隔. property 动画系统能让你设定以下动画要素: 1.持续时间:指定动画的持续显示时间.默认的时长是300毫秒. 2.插值因子:指定属性值的变化方式,表示为关于动画已显示时间的函数.