10

わかりました、その中ViewFlipperに 3 つがLinearLayoutsネストされています。デフォルトでは最初のものを表示します。このコード:

// Assumptions in my Activity class:
// oldTouchValue is a float
// vf is my view flipper
@Override
public boolean onTouchEvent(MotionEvent touchEvent) {
  switch (touchEvent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
      oldTouchValue = touchEvent.getX();
      break;
    }
    case MotionEvent.ACTION_UP: {
      float currentX = touchEvent.getX();
      if (oldTouchValue < currentX) {
        vf.setInAnimation(AnimationHelper.inFromLeftAnimation());
        vf.setOutAnimation(AnimationHelper.outToRightAnimation());
        vf.showNext();
      }
      if (oldTouchValue > currentX) {
        vf.setInAnimation(AnimationHelper.inFromRightAnimation());
        vf.setOutAnimation(AnimationHelper.outToLeftAnimation());
        vf.showPrevious();
      }
      break;
    }
    case MotionEvent.ACTION_MOVE: {
      // TODO: Some code to make the ViewFlipper
      // act like the home screen.
      break;
    }
  }
  return false;
}

public static class AnimationHelper {
  public static Animation inFromRightAnimation() {
    Animation inFromRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, +1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromRight.setDuration(350);
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
  }

  public static Animation outToLeftAnimation() {
    Animation outtoLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, -1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoLeft.setDuration(350);
    outtoLeft.setInterpolator(new AccelerateInterpolator());
    return outtoLeft;
  }

  // for the next movement
  public static Animation inFromLeftAnimation() {
    Animation inFromLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, -1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromLeft.setDuration(350);
    inFromLeft.setInterpolator(new AccelerateInterpolator());
    return inFromLeft;
  }

  public static Animation outToRightAnimation() {
    Animation outtoRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, +1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoRight.setDuration(350);
    outtoRight.setInterpolator(new AccelerateInterpolator());
    return outtoRight;
  }
}

...ビューの反転を処理しますが、アニメーションは非常に「オン/オフ」です。誰かが最後の部分で私を助けてくれるかどうか疑問に思っています。LinearLayouts にアクセスできると仮定すると、deltaX と deltaY に基づいてレイアウトの位置を設定できる方法はありますか?

誰かが私にこのリンクをくれて、これを行う方法のヒントについてメソッドを参照する必要があると言いましたapplyTransformationが、この同じ動作を繰り返す方法がわかりません.

4

2 に答える 2

10

指を動かしながらビューを移動するのは簡単です:

case MotionEvent.ACTION_MOVE:
    final View currentView = vf.getCurrentView();
    currentView.layout((int)(touchEvent.getX() - oldTouchValue), 
            currentView.getTop(), currentView.getRight(), 
            currentView.getBottom());
break;

現在、これは現在のビューのみを移動し、隣接するビューは移動しません。まだテストしていませんが、おそらく getChildAt で取得できます。

vf.getChildAt(vf.getDisplayedChild() - 1); // previous
vf.getChildAt(vf.getDisplayedChild() + 1); // next

それが役立つことを願っています。

于 2010-04-10T18:46:15.010 に答える
1

私があなたの要求を理解した場合、この効果はビュー ページャーを使用して実装する必要があります。

次のようになります。

ここに画像の説明を入力

于 2011-10-12T04:55:09.333 に答える