第一种:TranslateAnimation 动画效果演示:

public void move(View view){//传统动画效果TranslateAnimation animation=new TranslateAnimation(0, 500, 0, 0);//时间animation.setDuration(500);//设置移动后的位置不恢复animation.setFillAfter(true);ImageButton img=(ImageButton) findViewById(R.id.img);TextView tv=(TextView) findViewById(R.id.lab);//设置动画效果  控件img.startAnimation(animation);tv.startAnimation(animation);Toast.makeText(this, "移动时间", Toast.LENGTH_SHORT).show();}

XML 配置按钮时间

<Button    android:gravity="center"    android:layout_marginTop="500sp"    android:layout_marginStart="30sp"    android:layout_marginLeft="30sp"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="移动按钮"    android:id="@+id/btn"    android:onClick="move"

使用-------------使用ObjectAnimator----------360

//-------------使用ObjectAnimator----------
ObjectAnimator animator=new ObjectAnimator();
//animator.ofFloat(img, "translationY", 0,100).setDuration(1000).start();
if(flag)
{
animator.ofFloat(img, "Y", 0,300).setDuration(1000).start();
animator.ofFloat(img, "X", 0,300).setDuration(1000).start();
animator.ofFloat(img, "rotation", 0,360).setDuration(1000).start();
flag=false;

}
else
{
animator.ofFloat(img, "Y", 300,0).setDuration(1000).start();
animator.ofFloat(img, "X", 300,0).setDuration(1000).start();
animator.ofFloat(img, "rotation", 3600,0).setDuration(1000).start();
flag=true;
}

PropertyValuesHolder对象的使用

/** * 跟上面不同的是代码优化了 */public void propteValueHolderDemo(){ImageButton img=(ImageButton) findViewById(R.id.img);PropertyValuesHolder pro1=PropertyValuesHolder.ofFloat("rotation", 0,360F);PropertyValuesHolder pro2=PropertyValuesHolder.ofFloat("x", 0,300);PropertyValuesHolder pro3=PropertyValuesHolder.ofFloat("y", 0,300);ObjectAnimator.ofPropertyValuesHolder(img,pro1,pro2,pro3).setDuration(1000).start();}

/** * 按顺序 演示动画效果 */public void PlaySequentiallyDemo(){ImageButton img=(ImageButton) findViewById(R.id.img);ObjectAnimator animator1=ObjectAnimator.ofFloat("img","X",0,360F);ObjectAnimator animator2=ObjectAnimator.ofFloat("img","Y",0,360F);AnimatorSet set=new AnimatorSet();set.playSequentially(animator1,animator2);set.setDuration(1000);set.start();}

更多相关文章

  1. TextView使用Paint设置下划线删除线效果
  2. Android 图片平铺效果bitmap
  3. Android 获取系统时间的三种方式
  4. Android使用RecyclerView实现瀑布流效果的列表展示
  5. Android实现Banner轮播效果
  6. android: slide 滑动动画效果
  7. Android实现win8磁铁效果
  8. Android垂直跑马灯效果
  9. android 弹性效果

随机推荐

  1. 【Android-FaceBook】facebook Android配
  2. android开发给linearlayout设置边框
  3. Android(安卓)APPT2 报异常处理
  4. Android中的网络编程系列(一):URLConnect
  5. Android(安卓)Studio中如何新建assets文
  6. Android(安卓)SDK Manager 代理服务器设
  7. Android遇到的异常及解决方法
  8. 描述清点击 Android(安卓)Studio 的 buil
  9. Android(安卓)Binder机制学习总结(三)-Se
  10. ViewPager实现无限循环切换和手势滑动效