Android软键盘遮挡布局的解决办法

Android软键盘遮挡布局的解决办法,第1张

概述AndroidBug5497Workaround.classpublicclassAndroidBug5497Workaround{//Formoreinformation,seehttps://issuetracker.google.com/issues/36911528//Tousethisclass,simplyinvokeassistActivity()onanActivitythatalreadyhasitscontentvi

AndroIDBUG5497Workaround.class@H_404_1@

public class AndroIDBUG5497Workaround {    // For more information, see https://issuetracker.Google.com/issues/36911528    // 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);    }}

AndroIDBUG5497Workaround.assistActivity(this);@H_404_1@

参考:@H_404_1@Android爬坑之旅:软键盘挡住输入框问题的终极解决方案Android How to adjust layout in Full Screen Mode when softkeyboard is visible 总结

以上是内存溢出为你收集整理的Android软键盘遮挡布局的解决办法全部内容,希望文章能够帮你解决Android软键盘遮挡布局的解决办法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1060013.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存