Tuesday, 15 July 2014

android - Animate Window Layout Change -



android - Animate Window Layout Change -

i've got dialogfragment, centered on screen, i'm trying move out of way of on screen keyboard, if should appear, because it's not ux experience keyboard cover on parts of window when there's unused screen real estate farther up.

suppose i've solved problem of detecting keyboard appearing or disappearing, e.g. how check visibility of software keyboard in android? .

currently go move window out of way doing this:

... final windowmanager.layoutparams params = dialog.getwindow().getattributes(); params.gravity = gravity.top; params.verticalmargin = .1f; //or whatever dialog.getwindow().setattributes(params); ...

this works fine, window jerks place, isn't pleasant ux experience. window in question has successful come in , exit animation - , these work appropriately after window layout change. how can farther animate window between windowmanager.layoutparams changes?

(i'd prefer if possible maintain working in terms of layout {of the} / {within the} http://developer.android.com/reference/android/view/window.html rather than, say, forcing dialogfragment activity's layout , animating within there).

i didn't have time wait bounty expire, coded below stop gap until can improve solution. in case helps else, or gives them thought bounty-worthy answer, did. however, suspect inefficient hell, since assume forces window relayout every animation frame rather panning bitmap across screen. isn't of of course, critical bit:

// not shown: setting currentverticalmargin, targetverticalmargin, or calling 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 it's capped @ "going way target" , no further, // , has 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(); }

android android-layout

No comments:

Post a Comment