平时赶项目,脑子里时常会出现以下灵感特效,但是时间太紧张了,所以只敢想,实际去做的也抽不出时间,下面我会写一系列的微博来实现以下特效。今天是第一天,就拿简单的效果来练手。
图片的旋转
其实好多地方我们都会用到,比如刷新列表的时候,或者清理缓存的时候等等都可以根据自己的想象去添加一些特效。
做图片的旋转其实最重要的就是,写一个属性的配置文件(xml),控制旋转的样式。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="359"
android:duration="800"
android:repeatCount="-1"
/>
</set>
android:fromDegrees 起始的角度度数
android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大360即可
android:pivotX 旋转中心的X坐标
android:pivotY 旋转中心的Y坐标
浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心
android:duration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。
android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止
下面就是android代码:
public class RotateActivity extends AppCompatActivity {
//旋转的图片
ImageView rotate;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rotate);
//加载旋转的属性
final Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.rotate);
rotate = (ImageView) findViewById(R.id.imageView);
//控制旋转的速度(匀速,加速)
LinearInterpolator lin = new LinearInterpolator();
operatingAnim.setInterpolator(lin);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//停止旋转
rotate.clearAnimation();
}else{
//开始旋转
rotate.startAnimation(operatingAnim);
}
}
});
setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果