simplifying more complex problem.
i have alertdialog view dialog.xml (i might wrong , problem has nothing alertdialog, views in general):
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> // <imageview 48dp x 48dp/> imageview profile photo <edittext android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="top" android:maxlines="5" android:inputtype="textmultiline" android:scrollbars="vertical" android:scrollhorizontally="false"/> // <imageview 48dp x 48dp> imageview send button. </linearlayout>
i need whole dialog on bottom, right above keyboard, it's similar how chat programs have it. need floating dialog, because it's not tied 1 place in parent view.
i (in client code) achieve that:
dialog.show(); // above dialog window window dialog.getwindow(); window.setgravity(gravity.bottom); window.setlayout(layoutparams.match_parent, layoutparams.wrap_content); window.setbackgrounddrawable(new colordrawable(color.transparent)); window.setsoftinputmode(windowmanager.layoutparams.soft_input_state_always_visible);
now when type, edit field correctly expands 5 lines (from bottom up). if type fast (press enter create new lines fast), dialog expand animation (the height increases downward) slower dialog shifts animation. causes 1-2 seconds when dialog appears floating in air, little gap between lower border , keyboard.
how can prevent (eliminate space in between)? or make animation take 0 sec?
to clarify: not need disable animation dialog popup/dismiss. when window expands fast (for example creating new lines), window gets shifted up, while height not compensate shift fast enough leaving small temporary (1-2sec) gap in between dialog , keyboard. might fundamental problem floating views in general (i tried using popupwindow same effect).
dialog gap:
becomes after 1-2 sec (when expand animation catches up):
found solution on own after lot of digging through stack overflow answers no results.
the idea expand entire dialog first full screen, have transparent overlay view covering empty parts.
the dialog.xml looks this:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- transparent view extends on entire screen , push comment view bottom --> <view android:id="@+id/overlay" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/transparent"/> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:background="@android:color/white" android:orientation="horizontal"> // <imageview 48dp x 48dp/> imageview profile photo <edittext android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="top" android:maxlines="5" android:inputtype="textmultiline" android:scrollbars="vertical" android:scrollhorizontally="false"/> // <imageview 48dp x 48dp> imageview send button. </linearlayout> </linearlayout>
and java code:
public void showdialog() { view content = activity.getlayoutinflater().inflate(r.layout.dialog, null, false); // makes top linearlayout background transparent, without this, // white covering fullscreen. content.setbackgrounddrawable(new colordrawable(color.transparent)); dialog dialog = new alertdialog.builder(context) .setview(content).create(); dialog.show(); // needs done before window changes window window dialog.getwindow(); window.setlayout(layoutparams.match_parent, layoutparams.match_parent); window.setbackgrounddrawable(new colordrawable(color.transparent)); window.setsoftinputmode(windowmanager.layoutparams.soft_input_state_always_visible); view overlay = content.findviewbyid(r.id.overlay); overlay.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { if (dialog.isshowing()) { dialog.cancel(); } } }); }