简化更复杂的问题.
我有一个带有此视图dialog.xml的AlertDialog(我可能错了,这个问题与AlertDialog无关,但一般来说是Views):
<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>
Run Code Online (Sandbox Code Playgroud)
我需要将整个对话框放在键盘正上方的底部,以便它与聊天程序的方式类似.我需要它作为浮动对话框,因为它不依赖于父视图中的任何一个位置.
我这样做(在客户端代码中)来实现:
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);
Run Code Online (Sandbox Code Playgroud)
现在,当我输入时,编辑字段正确地扩展到最多5行(从下往上).但是如果输入太快(按Enter键快速创建新线条),对话框展开动画(高度向下增加)比对话框向上移动动画要慢.当对话框看起来漂浮在空中时,这会导致1-2秒,其下边框和键盘之间有一点间隙.
我怎样才能防止这种情况(消除它们之间的这个空间)?或者让动画花费0秒?
澄清一下:我不需要为对话框弹出/关闭禁用动画.当窗口扩展太快时(例如通过创建新线条),窗口向上移动,而高度不能足够快地补偿移位,在对话框和键盘之间留下一个小的临时(1-2秒)间隙.这可能是浮动视图的基本问题(我尝试使用PopupWindow具有相同的效果).
对话与差距:

在1-2秒之后变成这个(当扩展动画最终赶上时):

我不知道如何才能在C++中完成这项工作.
意图是:
pair<int, int> foo() {
if(cond) {
return std::make_pair(1,2);
}
return NULL; //error: no viable conversion from 'long' to 'pair<int, int>
}
void boo() {
pair<int, int> p = foo();
if (p == NULL) { //error: comparison between NULL and non-pointer ('int, int' and NULL)
// doA
} else {
int a = p.first;
int b = p.second;
// doB
}
}
Run Code Online (Sandbox Code Playgroud)
由于我不能在C++中使用return NULL,这是我的第二次尝试:
pair<int, int>* foo() {
if(cond) {
return &std::make_pair(1,2); //error: returning address of local temporary object) …Run Code Online (Sandbox Code Playgroud)