Пример #1
0
  /** Toggle the Logs View visibility with a nice animation. */
  public void toggleLogsView(boolean showView) {
    final View logsView = findViewById(R.id.logs_layout);
    final View bodyView = findViewById(R.id.container);
    final FrameLayout.LayoutParams logsLayoutParams =
        (FrameLayout.LayoutParams) logsView.getLayoutParams();
    final int startLogsY, endLogsY, startBodyY, endBodyY;

    if (showView) {
      // The logsView height set in XML is a placeholder, we need to compute at runtime
      // how much is 0.4 of the screen height.
      int height = (int) (0.4 * mDrawerLayout.getHeight());

      // The LogsView is hidden being placed off-screen with a negative bottomMargin.
      // We need to update its height and bottomMargin to the correct runtime values.
      logsLayoutParams.bottomMargin = -logsLayoutParams.height;
      logsView.setLayoutParams(logsLayoutParams);
      logsLayoutParams.height = height;

      // Prepare the value for the Show animation.
      startLogsY = logsLayoutParams.bottomMargin;
      endLogsY = 0;
      startBodyY = 0;
      endBodyY = logsLayoutParams.height;
    } else {
      // Prepare the value for the Hide animation.
      startLogsY = 0;
      endLogsY = -logsLayoutParams.height;
      startBodyY = logsLayoutParams.height;
      endBodyY = 0;
    }
    final int deltaLogsY = endLogsY - startLogsY;
    final int deltaBodyY = endBodyY - startBodyY;
    Animation a =
        new Animation() {
          @Override
          protected void applyTransformation(float interpolatedTime, Transformation t) {
            logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime);
            logsView.setLayoutParams(logsLayoutParams);
            bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime));
          }
        };
    a.setDuration(500);
    logsView.startAnimation(a);
  }