android key board covers edittextview

public class AndroidBug5497Workaround {

// For more information, see https://code.google.com/p/android/issues/detail?id=5497

// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.

public static voidassistActivity(Activity activity) {

newAndroidBug5497Workaround(activity);

}

privateViewmChildOfContent;

private intusableHeightPrevious;

privateFrameLayout.LayoutParamsframeLayoutParams;

privateAndroidBug5497Workaround(Activity activity) {

FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);

mChildOfContent= content.getChildAt(0);

mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(newViewTreeObserver.OnGlobalLayoutListener() {

public voidonGlobalLayout() {

possiblyResizeChildOfContent();

}

});

frameLayoutParams= (FrameLayout.LayoutParams)mChildOfContent.getLayoutParams();

}

private voidpossiblyResizeChildOfContent() {

intusableHeightNow = computeUsableHeight();

if(usableHeightNow !=usableHeightPrevious) {

intusableHeightSansKeyboard =mChildOfContent.getRootView().getHeight();

intheightDifference = usableHeightSansKeyboard - usableHeightNow;

if(heightDifference > (usableHeightSansKeyboard/4)) {

// keyboard probably just became visible

frameLayoutParams.height= usableHeightSansKeyboard - heightDifference;

}else{

// keyboard probably just became hidden

frameLayoutParams.height= usableHeightSansKeyboard;

}

mChildOfContent.requestLayout();

usableHeightPrevious= usableHeightNow;

}

}

private intcomputeUsableHeight() {

Rect r =newRect();

mChildOfContent.getWindowVisibleDisplayFrame(r);

return(r.bottom- r.top);

}

}


copy from stackoverflow

how to use:AndroidBug5497Workaround.assistActivity(this);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容