版本:2.4.3
现象:安卓键盘底部虚拟,获取键盘高度不正确,有遮挡
这种情况怎么解决
改android工程代码,给状态栏计算进去
具体怎么改可以说一下吗,对原声不太熟
怎么加你QQ?我给你个文件
991609424 我的qq
private void setTopMargin(int topMargin) {
int vh = getHeight();
int sh = getStatuBarHeight(this.getContext());
int h = vh + sh;
mTopMargin = topMargin;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mEditText.getLayoutParams();
layoutParams.topMargin = mTopMargin - h;
setLayoutParams(layoutParams);
requestLayout();
}
public int getStatuBarHeight(Context context){
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
return context.getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
if ((Cocos2dxEditText.this.mTopMargin == 0 || r.bottom != Cocos2dxEditText.this.mTopMargin) && r.bottom != getRootView().getHeight()) {
Cocos2dxEditText.this.setTopMargin(r.bottom);
}
//再楼上的基础拓展了一下,解决两个问题,部分机型输入框和输入法之间存在间隙,如果是顶部输入框在键盘弹出的时候输入框会被挤出到屏幕外。
//目前已知还有一个问题,第一次弹出的时候重新计算EditBox的位置会导致屏幕抖一下
//该方法在mLastBottom和Cocos2dxEditBox.this.itemY值发生变更的时候调用。Cocos2dxEditBox.this.itemY默认值-1
private void setTopMargin() {
//mLastBottom 即是registKeyboardVisible中的r.bottom且值不等于getRootView().getHeight(),在registKeyboardVisible缓存下来,存下来itemY变更的时候重新计算,EditBox位置
int bottom = mLastBottom;
if (bottom > 0 && bottom != getRootView().getHeight()) {
//itemY EditBox-android.cpp 的 EditBox::show传过来的取值 showInfo.y,在入口show的时候存下来。
if (Cocos2dxEditBox.this.itemY > 0) {
//根据输入框得位置计算EditBox得位置,最大不得超过mScreenHeight不然会被挤压到看不到,最小不得超过bottom不然和输入法有间隙
//本计算方法并没有特别严谨,属于大约计算一个安全值
bottom = Math.min(mScreenHeight, Math.max(bottom, getRootView().getHeight() - Cocos2dxEditBox.this.itemY + getHeight() + getStatusBarHeight()));
} else {
//据输入框得位置计算EditBox得位置,最大不得超过mScreenHeight不然会被挤压到看不到.理论可以再大一点,但是没有找到最大边际值,所以这是个大约安全编辑。
bottom = Math.min(mScreenHeight, bottom);
}
if (Cocos2dxEditText.this.mTopMargin == 0 || bottom != mTopMargin) {
mTopMargin = bottom;
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mEditText.getLayoutParams();
layoutParams.topMargin = mTopMargin - getHeight();
//Log.i(TAG, "键盘日志,mTopMargin = " + mTopMargin + ",layoutParams.topMargin=" + layoutParams.topMargin + ",bottom=" + bottom+",mScreenHeight="+mScreenHeight);
setLayoutParams(layoutParams);
requestLayout();
}
}
}[EditBox.zip|attachment](upload://nNwaWB1x87zIgCOm6PcCDMh1iGR.zip) (12.8 KB)
翻遍论坛没有找到一个可行的解决方案,痛定思痛自己研究解决了一下。不确定在特殊机型是否仍然有问题,目前可以解决已知的几个比较蛋疼的问题。
我也遇到了,不过 引擎组大佬帮忙解决了!
你看看 引擎组大佬 帮我解决的办法
目前还没有玩家反应有问题!
原理都一样,我多补充几个细节。同时多解决了输入如果在屏幕顶部,输入的时候会被推到屏幕外的问题。
你这种在阿语输入法的输入。在输入框输入过内容后。在点击输入框。会被挡住
mark 一下,一直被遮挡了这输入框