Android: how to prevent jumping / blinking views when trying to replace keyboard with view

I hide the keyboard. If I immediately make the view visible, a flash appears above the keyboard, and then it disappears in place of the keyboard.

If I wait for the keyboard to hide / show and resize my layout (using onSizeChanged of my global layout) and then try to make the view visible, in many cases the system does not reevaluate my layouts correctly (perhaps because I make the view visible in some way) is that weird part of the lifecycle of a layout change?) So in many cases I just don't see what is shown. Sometimes a strange space above the keyboard must be hidden at the viewing location. If I post a message (Runnable) and then call requestLayout () or make it appear visible in the next frame, that's not good because it flashes again, of course.

So, basically I want to know the exact frame when the keyboard will resize my views so that I can make them visible / invisible and prevent the different view structures / sizes from flickering. If I wait for onSizeChanged, it seems like it's too late.

I was really hoping the system would behave correctly and re-size my views and place them in the right places, but if done in onSizeChanged it won't work right.

+3


source to share


1 answer


I ended up doing the following:

  • disable main screen resizing between hidden parts and waiting for the keyboard to appear.
  • Allow resizing (and triggering resizing) after keyboard is displayed.


@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (resizingEnabled) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    } else {
        setMeasuredDimension(getWidth(), getHeight());
    }
}

      

0


source







All Articles