第一次旋转结束,拨杆能够回去;第二次旋转结束,拨杆不能回去
老师,这是我的代码。我启动模拟器以后,发现第一次旋转结束以后,拨杆能够回到正确位置;可是,第二次旋转结束以后,拨杆就不动了,相当于没有执行mBarOut函授,求解
package com.My_Music.Music_Guess.ui;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
public class MainActivity extends Activity {
//唱片旋转动画定义
private Animation mPanAnim; //圆盘动画
private LinearInterpolator mPanLin;
private Animation mBarInAnim; //拨杆(开启唱片旋转)
private LinearInterpolator mBarInLin;
private Animation mBarOutAnim; //拨杆(结束唱片旋转)
private LinearInterpolator mBarOutLin;
//唱片旋转动画定义结束
private ImageButton mStarPlay; //唱片开启按钮
private ImageView mViewPan; //盘片
private ImageView mViewBar; //拨杆
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//盘片部分
// 初始化圆盘动画
mPanAnim=AnimationUtils.loadAnimation(this,R.anim.pan_rotate);
mPanLin=new LinearInterpolator();
mPanAnim.setInterpolator(mPanLin);
mPanAnim.setFillAfter(true);
mPanAnim.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
mViewBar.startAnimation(mBarOutAnim);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}});
//初始化拨杆(开始)动画
mBarInAnim=AnimationUtils.loadAnimation(this,R.anim.bar_in);
mBarInLin=new LinearInterpolator();
mBarInAnim.setInterpolator(mBarInLin);
mBarInAnim.setFillAfter(true);
mBarInAnim.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
mViewPan.setAnimation(mPanAnim);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}});
//初始化拨杆(结束)动画
mBarOutAnim=AnimationUtils.loadAnimation(this, R.anim.bar_out);
mBarOutLin=new LinearInterpolator();
mBarOutAnim.setInterpolator(mBarOutLin);
mBarOutAnim.setFillAfter(true);
mBarOutAnim.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}});
mStarPlay=(ImageButton)findViewById(R.id.pan_play);
mViewPan=(ImageView)findViewById(R.id.imageView2);
mViewBar=(ImageView)findViewById(R.id.imageView5);
mStarPlay.setOnClickListener(new OnClickListener(){ //当点击
@Override
public void onClick(View arg0) {
StartPlayButton();
}});
}
private void StartPlayButton()
{
mViewBar.startAnimation(mBarInAnim);
}
@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;
}
}