当前位置: 代码迷 >> Android >> android卡通片-Property Animation
  详细解决方案

android卡通片-Property Animation

热度:226   发布时间:2016-04-28 02:47:28.0
android动画-Property Animation

转载注明出处: http://blog.csdn.net/forwardyzk/article/details/42741953 

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>


案例代码下载: http://download.csdn.net/detail/forwardyzk/8365189

效果图:



  
  

 



   
  相关解决方案