- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 PopupWindow 锚定在一个按钮上(在顶部)。 PopupWindow 包含一个 ScrollView。PopupWindow 处于 SOFT_INPUT_ADJUST_RESIZE 模式并使用偏移定位
代码:
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
window.showAtLocation(parent, Gravity.NO_GRAVITY, xPos, yPos);
屏幕:
base screen http://imageshack.us/a/img38/7771/basescreen.png
当软键盘出现时,我有这个(顶部按钮被隐藏):
what i have screen http://imageshack.us/a/img21/6396/whatihavescreen.png
我想要:
PopupWindow 锚定在 Button 上并调整了大小。
what i have screen http://imageshack.us/a/img805/3302/whatiwantscreen.png
提前致谢!
最佳答案
自己努力...这不是我开发的最佳解决方案,但无论如何......它有效......
第 1 部分:出现 SoftKeyboard 时调整 PopupWindow 的大小
在内容 View 上使用 OnGlobalLayoutListener
contentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
int baseHeight = 0;
@Override
public void onGlobalLayout() {
if(resized) {
return;
}
if(baseHeight <= 0) {
baseHeight = contentView.getHeight();
return;
}
final int diff = baseHeight - contentView.getHeight();
if(diff > 0) {
// keyboard is visible
window.update( - 1, baseHeight - diff - yPos);
resized = true;
}
}
});
完成此操作后,即使隐藏了 SoftKeyboard,PopupWindow 也会保持调整大小。 GlobalLayout 事件未触发,因为 PopupWindow 较小。
第 2 部分: 使用伪造的 PopupWindow 来了解 SoftKeyboard 是否被隐藏(脏 :()
先假后真
buildFakePopupWindow(rootHeight);
window.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
if(fakeWindow != null) {
fakeWindow.dismiss();
}
}
});
fakeWindow.showAtLocation(parent, Gravity.NO_GRAVITY, xPos, yPos);
在假的上注册一个 GlobalLayoutListener
final View fakeContentView = fakeWindow.getContentView();
fakeContentView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
int baseHeight = 0;
@Override
public void onGlobalLayout() {
if(baseHeight <= 0) {
baseHeight = fakeContentView.getHeight();
return;
}
final int diff = baseHeight - fakeContentView.getHeight();
if(diff <= 0 && resized) {
window.update( - 1, WindowManager.LayoutParams.WRAP_CONTENT);
resized = false;
}
}
});
我很确定这是一个肮脏的解决方案,但我没有找到另一种方法。
关于android - 锚定 PopupWindow 和 SOFT_INPUT_ADJUST_RESIZE android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13583473/
我用了SOFT_INPUT_ADJUST_RESIZE为了在键盘弹出时显示所有内容。 按照文档,我添加了新的代码 fragment : if (Build.VERSION.SDK_INT >= Bui
我有一个 PopupWindow 锚定在一个按钮上(在顶部)。 PopupWindow 包含一个 ScrollView。PopupWindow 处于 SOFT_INPUT_ADJUST_RESIZE
我有以下自定义 View DialogFragment。 当我点击 EditText 时,会显示软键盘。目前,观察结果是 对话框的位置有点“上推”。 对话框未调整大小且对话框内容被阻止。 这是它的样子
我在主 Activity 的 onCreate 中有以下代码: getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_
我是一名优秀的程序员,十分优秀!