在setContentView下加上下面代码即可


AndroidBug5497Workaround.assistActivity(this);



AndroidBug5497Workaround类代码如下


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 void assistActivity (Activity activity) {        new AndroidBug5497Workaround(activity);    }    private View mChildOfContent;    private int usableHeightPrevious;    private FrameLayout.LayoutParams frameLayoutParams;    private AndroidBug5497Workaround(Activity activity) {        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);        mChildOfContent = content.getChildAt(0);        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {            public void onGlobalLayout() {                possiblyResizeChildOfContent();            }        });        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();    }    private void possiblyResizeChildOfContent() {        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 int computeUsableHeight() {        Rect r = new Rect();        mChildOfContent.getWindowVisibleDisplayFrame(r);        return (r.bottom - r.top);    }}


解决方法来源:

http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006


全屏WebView也可用。

更多相关文章

  1. android 代码设置apn
  2. Android 通过代码执行Linux 命令 echo 命令
  3. android 反编译和代码解读
  4. 第一行代码 Android
  5. android对话框代码中设置背景为透明
  6. android取得手机屏幕大小DisplayMetrics的核心代码
  7. Android代码分析
  8. Android源代码在线浏览网站列表
  9. android代码编写布局和控件

随机推荐

  1. android分页查询获取系统联系人信息
  2. ch07 Android(安卓)日期与时间对话框
  3. Android(安卓)弧形进度条
  4. Android(安卓)getSystemService
  5. Android重启应用程序代码
  6. 【Android外文翻译 - 02】判断是否可以使
  7. Android第一个程序——打招呼
  8. Android动态创建ListView视图,动态增加和
  9. android生成json
  10. android 重启自身app