转载注明出处: http://blog.csdn.net/forwardyzk/article/details/42741953
Property Animation 属性动画,这个是在Android 3.0中才引进的。
Property Animation其改变的是对象属性对应的值,应用于任何对象,而Tween Animation更改的是绘画的效果,其属性值是没有变化的。
部分示例代码:
<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
效果图: