Android简单明了的使用属性动画ObjectAnimator 旋转 平移 渐变 缩放 透明监听事件
16lz
2021-01-24
//属性动画(text1是你要想动的View float translationX = text1.getTranslationX(); //获得当前按钮的位置 ObjectAnimator animator = ObjectAnimator.ofFloat(text1, "translationX", 300, translationX); //放大 ObjectAnimator scaleX = ObjectAnimator.ofFloat(text1, "scaleX", 1f, 3f, 1f); //透明 ObjectAnimator alpha = ObjectAnimator.ofFloat(text1, "alpha", 1f, 0f, 1f); //旋转 ObjectAnimator rotation = ObjectAnimator.ofFloat(text1, "rotation", 0f, 360f); //背景渐变颜色 ObjectAnimator backgroundColor = ObjectAnimator.ofInt(text1, "backgroundColor", 0x00FFFFFF , 0x6600ff00); //不加它的话是闪光灯效果一样(在这里不加了 //backgroundColor.setEvaluator(new ArgbEvaluator()); //组合动画 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(animator).with(scaleX).with(alpha).with(rotation).before(backgroundColor); animatorSet.setDuration(5000); animatorSet.start(); //动画监听 animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); Toast.makeText(Main2Activity.this,"动画结束",Toast.LENGTH_LONG).show(); } }); }
更多相关文章
- Android动画播放的常用方式
- android之Tabhost深入讲解二
- 安卓课程十八 RadioButton单选按钮的使用
- Android(安卓)标题栏上加一个返回按钮 超简单的返回
- Pair 了解一下
- [置顶] android 幻灯片效果之小方块渐入渐出
- Android(安卓)databinding RecycleView item 子控件点击事件
- Android打开摄像头拍照,并显示出来
- Android(安卓)属性动画(二)