1

ビューフリッパーでさまざまなレイアウトをめくるためのサンプル アプリケーションを作成しました。

XMLは基本的に(疑似コード)

<ViewFlipper>
<LinearLayout><TextView text:"this is the first page" /></LinearLayout>
<LinearLayout><TextView text:"this is the second page" /></LinearLayout>
<LinearLayout><TextView text:"this is the third page" /></LinearLayout>
</ViewFlipper>

そして Java コードでは、

public boolean onTouchEvent(MotionEvent event)
case MotionEvent.ACTION_DOWN {
   oldTouchValue = event.getX()
} case MotionEvent.ACTION_UP {
   //depending on Direction, do viewFlipper.showPrevious or viewFlipper.showNext
   //after setting appropriate animations with appropriate start/end locations
} case MotionEvent.ACTION_MOVE {
   //Depending on the direction
   nextScreen.setVisibility(View.Visible)
   nextScreen.layout(l, t, r, b) // l computed appropriately
   CurrentScreen.layout(l2, t2, r2, b2) // l2 computed appropriately
}

上記の疑似コードは、画面上でドラッグするときに (ホーム画面のように) viewflipper 内で線形レイアウトをうまく移動します。

問題は、nextScreen.setVisibility(View.VISIBLE) を実行するときです。次の画面が表示されるように設定されると、適切な位置に移動する前に画面上でちらつきます。(0の位置で見えるようになっていると思います。)

画面がちらつくことなく次の画面を読み込む方法はありますか? ちらつきがないように、画面の外にロード(表示)したい。

お時間をいただき、ありがとうございました。

4

1 に答える 1

3

+1。私はまったく同じ問題を抱えています。layout() および setVisible() 呼び出しを無効に切り替えてみました。

更新: 問題は、nextScreen ビューの可視性を設定する際の正しい順序であることが判明しました。layout() を呼び出す前に可視性を VISIBLE に設定すると、気づいたように位置 0 でちらつきが発生します。ただし、最初に layout() を呼び出すと、可視性が失われるため無視されます。これを修正するために、次の 2 つのことを行いました。

  1. 最初の layout() 呼び出しの前に、可視性を INVISIBLE に設定します。これは、layout() が実行されるという点で GONE とは異なります。表示されないだけです。
  2. 可視性を非同期的に VISIBLE に設定して、layout() と関連メッセージが最初に処理されるようにします。

コード内:

case MotionEvent.ACTION_DOWN:
    nextScreen.setVisibility(View.INVISIBLE); //from View.GONE

case MotionEvent.ACTION_MOVE:
    nextScreen.layout(l, t, r, b);
    if (nextScreen.getVisibility() != View.VISIBLE) {
    //the view is not visible, so send a message to make it so
    mHandler.sendMessage(Message.obtain(mHandler, 0));
}

private class ViewHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {
        nextScreen.setVisibility(View.VISIBLE);
    }
}

よりエレガントで簡単なソリューションを歓迎します!

于 2010-09-13T08:24:18.273 に答える