Android 滑动半圆旋转动画
时间: 2023-12-01 11:42:10 浏览: 245
以下是Android滑动半圆旋转动画的实现方法:
1.使用平移动画,只显示半圆:
```java
// 获取ImageView控件
ImageView iv = findViewById(R.id.iv);
// 设置ImageView为整个圆
iv.setImageResource(R.drawable.circle);
// 移动一半位置到屏幕外面
iv.setTranslationX(-iv.getWidth() / 2);
// 创建平移动画
ObjectAnimator translationAnimator = ObjectAnimator.ofFloat(iv, "translationX", 0f, -iv.getWidth() / 2);
translationAnimator.setDuration(1000);
// 创建旋转动画
ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(iv, "rotation", 0f, -180f);
rotationAnimator.setDuration(1000);
// 创建动画集合
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(translationAnimator, rotationAnimator);
animatorSet.start();
```
2.使用属性动画,实现ImageView轮盘跟随RecyclerView滑动做旋转动画:
```java
// 获取RecyclerView控件
RecyclerView recyclerView = findViewById(R.id.recyclerView);
// 设置RecyclerView的滑动监听器
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// 获取ImageView控件
ImageView iv = findViewById(R.id.iv);
// 计算旋转角度
float rotation = iv.getRotation() + dx;
// 设置旋转动画
ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(iv, "rotation", iv.getRotation(), rotation);
rotationAnimator.setDuration(0);
rotationAnimator.start();
}
});
```
阅读全文
相关推荐















