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