android 属性动画(缩放,渐变,移动,旋转)
程序员文章站
2024-03-24 12:16:16
...
首先设置一个图片,引入布局
<ImageView
android:id="@+id/iv_splash"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/i"
android:layout_gravity="center"
/>
第二步:初始化initData()
getSupportActionBar().hide();//隐藏标题栏
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();//这个好像是可以获取屏幕高度
int height = displayMetrics.heightPixels;//获取屏幕高度
//缩放---ofFloat用4个参数的ofFloat
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(iv_splash, "scaleX", 2, 1);
//渐变
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(iv_splash, "alpha", 0, 1);
//旋转
ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(iv_splash, "rotation", 0, 360);
//移动
ObjectAnimator objectAnimator4 = ObjectAnimator.ofFloat(iv_splash, "translationY", 0, height / 2 - iv_splash.getHeight() / 2);
//组合
AnimatorSet set = new AnimatorSet();
/**
* 动画执行
*/
set.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3).with(objectAnimator4);
set.setDuration(3000);
set.start();
第三步:给动画添加监听
/**
* 动画执行的监听
*/
set.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
//动画执行完后跳转到主activity
@Override
public void onAnimationEnd(Animator animation) {
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
上一篇: AJax控件的应用
推荐阅读
-
android 属性动画(缩放,渐变,移动,旋转)
-
Android模拟开关按钮点击打开动画(属性动画之平移动画)
-
Android模拟开关按钮点击打开动画(属性动画之平移动画)
-
Android动画 实现开关按钮动画(属性动画之平移动画)实例代码
-
android 动画 博客分类: Android 基础 android透明度缩放旋转平移
-
Android动画处理缩放,平移,旋转 博客分类: Android多媒体技术 旋转平移缩放安卓动画
-
Android中利用matrix 控制图片的旋转、缩放、移动
-
Android动画之渐变动画(Tween Animation)详解 (渐变、缩放、位移、旋转)
-
Android动画之渐变动画(Tween Animation)详解 (渐变、缩放、位移、旋转)
-
Android开发之图形图像与动画(二)Animation实现图像的渐变/缩放/位移/旋转