Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56741
  • 博文数量: 16
  • 博客积分: 408
  • 博客等级: 一等列兵
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 09:07
文章分类
文章存档

2012年(16)

我的朋友

分类: Java

2012-02-24 09:31:33

public class PenAnimActivity extends Activity {

TranslateAnimation anim;
TranslateAnimation anim2;
ImageButton b1;
ImageButton b2;
ImageButton b3;
ImageButton b4;
ImageButton b5;
boolean mIsAnim = false;
int mIsEachPenFlag = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
anim = new TranslateAnimation(0, 0, 0, 450);
anim2 = new TranslateAnimation(0, 0, 450, 0);
// anim.setInterpolator(new LinearInterpolator());
anim.setDuration(200);
anim.setFillAfter(true);

anim2.setDuration(200);
anim2.setFillAfter(true);

b1 = (ImageButton) findViewById(R.id.pen1);
b2 = (ImageButton) findViewById(R.id.pen2);
b3 = (ImageButton) findViewById(R.id.pen3);
b4 = (ImageButton) findViewById(R.id.pen4);
b5 = (ImageButton) findViewById(R.id.pen5);

b1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (mIsAnim == false) {
if (mIsEachPenFlag != 1) {
clearAllAnim();
if (getButton(mIsEachPenFlag) != null) {
getButton(mIsEachPenFlag).startAnimation(anim2);
}
mIsEachPenFlag = 1;
b1.startAnimation(anim);
}

// anim.startNow();

}
}
});

b2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (mIsAnim == false) {
if (mIsEachPenFlag != 2) {
clearAllAnim();
if (getButton(mIsEachPenFlag) != null) {
getButton(mIsEachPenFlag).startAnimation(anim2);
}
mIsEachPenFlag = 2;
b2.startAnimation(anim);
}

}
}
});

b3.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (mIsAnim == false) {
if (mIsEachPenFlag != 3) {
clearAllAnim();
if (getButton(mIsEachPenFlag) != null) {
getButton(mIsEachPenFlag).startAnimation(anim2);
}
mIsEachPenFlag = 3;
b3.startAnimation(anim);
}

}
}
});

b4.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (mIsAnim == false) {
if (mIsEachPenFlag != 4) {
clearAllAnim();
if (getButton(mIsEachPenFlag) != null) {
getButton(mIsEachPenFlag).startAnimation(anim2);
}
mIsEachPenFlag = 4;
b4.startAnimation(anim);
}

}
}
});

b5.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (mIsAnim == false) {
if (mIsEachPenFlag != 5) {
clearAllAnim();
if (getButton(mIsEachPenFlag) != null) {
getButton(mIsEachPenFlag).startAnimation(anim2);
}
mIsEachPenFlag = 5;
b5.startAnimation(anim);
}

}
}
});

anim.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
mIsAnim = true;
}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
mIsAnim = false;
}
});
}

private ImageButton getButton(int i) {
ImageButton a = null;
switch (i) {
case 1:
a = b1;
break;
case 2:
a = b2;
break;
case 3:
a = b3;
break;
case 4:
a = b4;
break;
case 5:
a = b5;
break;
}
return a;

}

private void clearAllAnim() {
b1.clearAnimation();
b2.clearAnimation();
b3.clearAnimation();
b4.clearAnimation();
b5.clearAnimation();
}

}
阅读(1454) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~