已更新
我有一个麻烦和棘手的活动,其中: -IF这是第一次打开应用程序,它将setContentView设置为名为flipper的布局,并且 -ELSE如果启动转到活动MainPage.Class
的意图现在,应用程序启动正常,但是鳍状肢布局在无限循环中每两秒左右一次又一次地加载
我的活动如下:
public class Tutorial extends MainActivity{
private ViewFlipper viewFlipper;
private float lastX;
private Tutorial mContext;
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper);
prefs = getSharedPreferences("yo.laststage", MODE_PRIVATE);
}
@Override
protected void onResume() {
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
class SwipeGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.in_from_left));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.out_to_left));
viewFlipper.showNext();
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.in_from_right));
viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.out_to_right));
viewFlipper.showPrevious();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
prefs.edit().putBoolean("firstrun", false).commit();
Intent i = new Intent(Tutorial.this, MainPage.class);
this.startActivity(i);
}
}
}
可能出现什么问题?