android动画效果演示
16lz
2021-01-23
第一种: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();}
更多相关文章
- TextView使用Paint设置下划线删除线效果
- Android 图片平铺效果bitmap
- Android 获取系统时间的三种方式
- Android使用RecyclerView实现瀑布流效果的列表展示
- Android实现Banner轮播效果
- android: slide 滑动动画效果
- Android实现win8磁铁效果
- Android垂直跑马灯效果
- android 弹性效果