2010-08-23 6 views
1

viewflipper에서 다른 레이아웃으로 넘기기위한 샘플 애플리케이션을 만들었습니다. (그냥 집처럼 화면에 드래그하면Android 홈 화면 설정시 효과 깜박임 문제가 발생했습니다. child.setvisibility (View.Visible)

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> 

그리고 자바 코드에서,

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 안쪽은 LinearLayouts 이동 작품 화면).

문제는 nextScreen.setVisibility (View.VISIBLE)입니다. 다음 화면이 보이도록 설정되면 해당 위치로 이동하기 전에 화면에서 깜박입니다. (0 위치에서 볼 수 있습니다.)

화면에서 깜박이지 않고 다음 화면을로드 할 수 있습니까? 나는 화면 밖으로 로딩 (가시화)되어 깜박 거리지 않도록하고 싶다.

시간을내어 도와 주셔서 감사합니다.

답변

3

+1. 나는 똑같은 문제를 겪고있다. 레이아웃() 및 setVisible() 호출을 아무런 효과없이 전환하려고했습니다.

업데이트 : 문제는 nextScreen보기의 표시 여부를 설정하는 올바른 순서로 나타납니다. 의 가시성을 calling layout() 전에 설정하면 눈치 채기 시작한 위치 0에서 깜박임이 발생합니다. 그러나 layout()을 먼저 호출하면 가시성이 GONE이므로 무시됩니다. 이 문제를 해결하기 위해 두 가지 일을했습니다.

  1. 첫 번째 layout() 호출 전에 가시성을 INVISIBLE로 설정합니다. 이것은 layout()이 실행된다는 점에서 GONE과 다르다. 단지 보이지 않는다.
  2. 비동기 VISIBLE에 시인성을 설정하므로 레이아웃()와 관련된 메시지 코드에서

먼저 처리된다

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); 
    } 
} 

더 우아한/쉬운 해결책은 환영합니다!

관련 문제