美文网首页
android key board covers edittex

android key board covers edittex

作者: 暮色雨林 | 来源:发表于2017-11-16 11:04 被阅读0次

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);

相关文章

网友评论

      本文标题:android key board covers edittex

      本文链接:https://www.haomeiwen.com/subject/wqxgbttx.html