Animation
一、两模四类一集
alpha/AlphaAnimation
scale/ScaleAnimation
translate/TranslateAnimation
rotate/RotateAnimation
AnimationSet
二、XML
res目录anim文件夹
a.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha/>
<scale/>
<translate/>
<rotate/>
</set>
public static Animation loadAnimation(Context context, int id)
三、动态
private Animation alpha;
alpha =new AlphaAnimation(0.1f, 1.0f);
四、使用
startAnimation(alpha)
使用动画集
AnimationSet set = new AnimationSet(true);
set.addAnimation(alpha);
set.addAnimation(rotate);
startAnimation(set);
五、代码
private Button start = null;
private ImageView show = null;
private Animation translateAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
start = (Button) findViewById(R.id.start);
show = (ImageView) findViewById(R.id.show);
translateAnimation = new TranslateAnimation(0, 200, 0, 200);
translateAnimation.setDuration(3000);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
show.setAnimation(translateAnimation);
show.startAnimation(translateAnimation);
}
});
}