예제 #1
0
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    float vx = Math.abs(velocityX); // 取其绝对值
    float vy = Math.abs(velocityY);
    // ----begin设置浮动框的弹出和收回--------------------
    if (vy > vx) {
      if (velocityY > 0) { // 设置弹出
        if (flag == false) {

          int height = myRelativeLayout.getHeight();
          Animation myTranslateAnimation = new TranslateAnimation(0, 0, -height, 0);
          myTranslateAnimation.setDuration(500);
          myRelativeLayout.setAnimation(myTranslateAnimation);
          myRelativeLayout.setVisibility(View.VISIBLE);

          flag = true;
        }

      } else if (velocityY < 0) { // 设置收回

        if (flag == true) {
          int height = myRelativeLayout.getHeight();
          Animation myTranslateAnimation = new TranslateAnimation(0, 0, 0, -height);
          myTranslateAnimation.setDuration(500);
          myRelativeLayout.setAnimation(myTranslateAnimation);
          myRelativeLayout.setVisibility(View.GONE);
          flag = false;
        }
      }

    } else
    // -----end设置浮动框的弹出和收回---------------------------------
    // -----begin设置左右滑动翻页-----------------------
    if (vx > vy) {
      if (velocityX > 0) { // 前一页
        if (myWebView.canGoBack()) {

          myWebView.goBack();

          int width = myWebView.getWidth();
          Animation myTranslateAnimation = new TranslateAnimation(0, width, 0, 0);
          myTranslateAnimation.setDuration(400);
          myWebView.setAnimation(myTranslateAnimation);
        }
      } else if (velocityX < 0) { // 后一页
        if (myWebView.canGoForward()) {

          myWebView.goForward();

          int width = myWebView.getWidth();
          Animation myTranslateAnimation = new TranslateAnimation(0, -width, 0, 0);
          myTranslateAnimation.setDuration(400);
          myWebView.setAnimation(myTranslateAnimation);
        }
      }
    }
    // -----end设置左右滑动翻页------------------------
    return false;
  }
예제 #2
0
  public boolean onDown(MotionEvent e) {
    if (flag == true) {
      int height = myRelativeLayout.getHeight();
      Animation myTranslateAnimation = new TranslateAnimation(0, 0, 0, -height);
      myTranslateAnimation.setDuration(500);
      myRelativeLayout.setAnimation(myTranslateAnimation);
      myRelativeLayout.setVisibility(View.GONE);
      flag = false;
    }

    return true;
  }
  @Override
  public void onBackPressed() {
    if (backScreen.getVisibility() == View.INVISIBLE) {
      backScreen.setVisibility(View.VISIBLE);

      AlphaAnimation screenAnim = new AlphaAnimation(0.5f, 0.5f);
      screenAnim.setDuration(0);
      screenAnim.setFillAfter(true);
      backScreen.setAnimation(screenAnim);

      resumeButton.setEnabled(true);
      exitButton.setEnabled(true);
    } else {
      backScreen.setVisibility(View.INVISIBLE);

      AlphaAnimation screenAnim = new AlphaAnimation(0f, 0f);
      screenAnim.setDuration(0);
      screenAnim.setFillAfter(true);
      backScreen.setAnimation(screenAnim);

      resumeButton.setEnabled(false);
      exitButton.setEnabled(false);
    }
  }