android adjustresize 布局混乱,Android adjustresize全屏无效问题
public classAndroidBug5497Workaround {//For more information, seehttps://code.google.com/p/android/issues/detail?id=5497//To use this class, simply invoke assistActivity() on an Activity that already
public classAndroidBug5497Workaround {//For more information, seehttps://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);
}privateView mChildOfContent;private intusableHeightPrevious;privateFrameLayout.LayoutParams frameLayoutParams;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() {int usableHeightNow =computeUsableHeight();if (usableHeightNow !=usableHeightPrevious) {int usableHeightSansKeyboard =mChildOfContent.getRootView().getHeight();int heightDifference = 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);
}
}
更多推荐


所有评论(0)