*补间动画
*透明度渐变
*旋转动画
*位移动画
*如果需要几个效果整合到一起,需要将所有效果全部放到set里
MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image=(ImageView)findViewById(R.id.image);
ImageView image2=(ImageView)findViewById(R.id.image2);
ImageView image3=(ImageView)findViewById(R.id.image3);
ImageView image4=(ImageView)findViewById(R.id.image4);
ImageView image5=(ImageView)findViewById(R.id.image5);
//加载动画
//透明度渐变
Animation animation=AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);
image.startAnimation(animation);
//旋转动画
Animation animation2=AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
image2.startAnimation(animation2);
Animation animation3=AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale);
image3.startAnimation(animation3);
Animation animation4=AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate);
image4.startAnimation(animation4);
Animation animation5=AnimationUtils.loadAnimation(MainActivity.this, R.anim.set);
image5.startAnimation(animation5);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 动画——旋转
android:repeatCount="infinite"重复旋转
android:fromDegrees="0"开始角度
android:toDegrees="360" 结束角度
android:pivotX="0"
android:pivotY="0"旋转中心
android:repeatMode="reverse"重复模式改为相反
-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="2000"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
>
</rotate>
scale.xml
<?xml version="1.0" encoding="utf-8"?>
<!--动画——缩放
android:fromXScale="1"
android:fromYScale="1"开始大小
android:toXScale="2"
android:toYScale="2"结束大小
android:repeatCount="infinite"重复执行
android:pivotX="50%"
android:pivotY="50%"缩放中心
-->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="2"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
>
</scale>
set.xml
<?xml version="1.0" encoding="utf-8"?>
<!--若要实现多个效果共同体现在同一个组件上,将各种效果文件全部写到set里
-->
<set>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:duration="2000"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="2"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-200"
android:fromYDelta="0"
android:toXDelta="200"
android:toYDelta="0"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:duration="2000"
/>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="1"
android:toAlpha="0"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
</set>
translate.xml
<?xml version="1.0" encoding="utf-8"?>
<!--动画——位移
-->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-200"
android:fromYDelta="0"
android:toXDelta="200"
android:toYDelta="0"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:duration="2000"
>
</translate>