Change the animated window layout

I have a DialogFragment, usually centered on the screen, that I am trying to get away from the screen keyboard screen if it appears because it is not a good UX experience for the keyboard over parts of the window when there is completely unused screen real estate further.

Suppose I solved a keyboard detection problem that appears or disappears, for example. How to check the visibility of a software keyboard in Android? .

I am currently going to move the window to the side by doing something like this:

... final WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); params.gravity = Gravity.TOP; params.verticalMargin = .1f; //or whatever dialog.getWindow().setAttributes(params); ... 

This works great, but the window suddenly appears in place, which is not a pleasant UX experience. The window in question has a successful animation of input and output - and they even work properly after changing the layout of the window. How can I further animate the window between windowManager.LayoutParams changes?

(I would prefer if you could continue to work in terms of the layout {of} / {inside} http://developer.android.com/reference/android/view/Window.html rather than, say, forcing DialogFragment in my mock activity and animate it inside).

+6
source share
1 answer

I did not have time to wait until the bounty expires, so I coded the bottom gap of the gap until I get a better solution. In case it helps someone else or gives them an idea for a decent answer, this is what I did. However, I suspect that it is ineffective, like all hell, since I assume that it forces the relay window of each frame of the animation, rather than just panning the bitmap across the screen. Of course, this is not all, but this is a critical bit:

 // Not shown: setting currentVerticalMargin, targetVerticalMargin, or calling this method private synchronized void restartVerticalMarginAnimator() { if (verticalMarginAnimator != null) { return; } final Dialog dialog = this.getDialog(); if (dialog == null) { return; } final WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); verticalMarginAnimator = new TimeAnimator(); verticalMarginAnimator.setTimeListener(new TimeListener() { @Override public void onTimeUpdate(TimeAnimator a, long totalTime, long deltaTime) { float stretch = targetVerticalMargin - currentVerticalMargin; float distance = WINDOW_ANIMATION_SPEED * deltaTime / 1000L; boolean finished = false; // Adjust distance so it capped at "going all the way to target" and no further, // and has the right sign if we're animating upward. if (distance > Math.abs(stretch)) { distance = stretch; finished = true; } else if (stretch < 0) { distance *= -1f; } // Move. currentVerticalMargin += distance; if (finished) { verticalMarginAnimator.end(); verticalMarginAnimator = null; } params.verticalMargin = currentVerticalMargin; dialog.getWindow().setAttributes(params); } }); verticalMarginAnimator.start(); } 
+2
source

Source: https://habr.com/ru/post/976757/


All Articles