般的效果闪烁问题的Andr​​oid主屏幕时,设置child.setvisibility(View.Visible)屏幕、效果、问题、Andr

2023-09-05 01:00:49 作者:一人一心一空城

我做了一个示例应用程序通过不同的布局翻转的viewflipper。

I have made a sample application to flip through different layouts in a viewflipper.

XML基本上是(伪code)

XML is basically (pseudo-code)

<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中的code,

And in Java code,

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
}

上面的伪code在屏幕上拖动(就像主屏幕)时效果很好动linearlayouts内viewflipper。

Above pseudo code works well moving linearlayouts inside viewflipper when dragging on the screen (just like the home screen).

现在的问题是,当我做nextScreen.setVisibility(View.VISIBLE)。在接下来的屏幕设置可见,它闪烁在屏幕上移动到合适的位置之前。 (我估计是在0位置可见。)

The problem is when I do nextScreen.setVisibility(View.VISIBLE). When the next screen is set visible, it flickers on the screen before moving to its appropriate position. (I guess it is made visible at 0 location.)

有没有办法来加载下一屏幕,不使其闪烁在屏幕上?我希望它被加载(可以看到)从屏幕,所以它不刺眼。

Is there a way to load the next screen without making it flicker on the screen? I want it to be loaded (made visible) out of screen so it doesn't flicker.

感谢您对我付出的时间和帮助!

Thank you very much for your time and help!

推荐答案

+1。我有完全相同的问题。我试着开关的布局()和的setVisible()调用没有效果。

+1. I'm having the exact same problem. I tried switching the layout() and setVisible() calls to no effect.

更新: 这个问题原来是在设置nextScreen视图的可见正确的顺序。如果设置能见度可见的在的调用布局(),你得到的闪烁在位置0,你注意到了。但是,如果你调用布局()首先,它就会被忽略,因为知名度已经一去不复返了。我做了两件事情来解决这个问题:

Update: The problem turns out to be the correct sequence in setting the visibility of the nextScreen view. If you set the visibility to VISIBLE before calling layout(), you get the flicker at position 0 as you noticed. But if you call layout() first, it gets ignored because the visibility is GONE. I did two things to fix this:

设置的知名度,看不见的第一个布局前()调用。这不同于布局()被执行极速 - 你只是看不到它 设置能见度可见异步,所以布局()和相关的消息首先被处理

在code:

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

更优雅/更容易的解决方案,欢迎!

More elegant/easier solutions are welcome!

 
精彩推荐
图片推荐