【发布时间】:2015-04-27 23:49:38
【问题描述】:
简化更复杂的问题。
我有一个带有这个视图 dialog.xml 的 AlertDialog(我可能错了,这个问题与 AlertDialog 无关,但一般来说是视图):
<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 for 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 for a send button.
</LinearLayout>
我需要将整个对话框放在键盘的底部,就在键盘的正上方,这样它就类似于聊天程序的样子。我需要它作为浮动对话框,因为它不绑定到父视图中的任何地方。
我这样做(在客户端代码中)是为了实现这一点:
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);
现在,当我键入时,编辑字段正确地扩展为最多 5 行(从下往上)。但是如果我输入太快(按回车快速创建新行),对话框展开动画(高度向下增加)比对话框向上移动动画慢。这会导致 1-2 秒的时间让对话框看起来漂浮在空中,其下边框和键盘之间有一点间隙。
我怎样才能防止这种情况(消除中间的这个空间)?还是让动画耗时 0 秒?
澄清一下:我不需要禁用对话框弹出/关闭的动画。当窗口扩展得太快(例如通过创建新行)时,窗口会向上移动,而高度不能足够快地补偿移动,在对话框和键盘之间留下一个小的临时(1-2 秒)间隙。这可能是浮动视图的基本问题(我尝试使用具有相同效果的 PopupWindow)。
有间隙的对话:
1-2 秒后变成这样(当展开动画终于赶上时):
【问题讨论】:
-
澄清一下:我不需要禁用对话框弹出/关闭的动画。我需要禁用对话框向下移动和高度扩展的动画。这可能是浮动视图的基本问题(我尝试使用具有相同效果的 PopupWindow)。
标签: android dialog android-animation android-alertdialog