在上一篇图片变为圆形的基础上,使其旋转
在app- res下创建一个anim文件夹,并创建一个img_xz的xml文件,
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="5000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
在activity_main文件中,仍然使用的是刚才的代码
<com.example.lenovo.a06266.CircleImageView
android:layout_marginTop="75dp"
android:id="@+id/imageView"
android:layout_centerHorizontal="true"
android:src="@drawable/xz"
android:layout_width="300dp"
android:layout_height="300dp" />
接下来就是java代码的实现
package com.example.lenovo.a06266;
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ImageView imageView=(ImageView)findViewById(R.id.imageView);
Animation animation= AnimationUtils.loadAnimation(this,R.anim.img_animation);
LinearInterpolator lin=new LinearInterpolator();
animation.setInterpolator(lin);
imageView.startAnimation(animation);
}
}
因为接下来写了有别的东西,所以有的包没导入,可以根据提示自己导包。