Phonegap - Android如何在软键盘可见时在全屏模式下调整布局 [英] Phonegap - Android How to adjust layout in Full Screen Mode when softkeyboard is visible

查看:407
本文介绍了Phonegap - Android如何在软键盘可见时在全屏模式下调整布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个三星Galaxy Tab 3的phonegap应用程序。当这个应用程序是在全屏模式下,软键盘隐藏文本输入字段,不可能滚动页面看到的内容。如何解决这个问题?

I am working on an phonegap app for a Samsung Galaxy Tab 3. When this application is in full screen mode, the softkeyboard hides the text input fields and it's impossible to scroll the page to see the content. how could I fix the problem?

推荐答案

在这个网站尝试几乎每一个可能的解决方案后,最后,我可以根据以下两个建议的解决方案找到一个工作:

After spending a day trying almost every possible solution in this website, nothing worked for me. At the end I was able to find a work around based on the following two proposed solutions:

http://stackoverflow.com/a/19494006/1435991

此链接显示了解决Android应用问题的解决方法;但是我没有在Android中工作的任何经验,所以问题是:如何包括这个和平的代码在Phonepap项目。

this link shows a workaround to fix the problem for an android app; however I don't have any experience working in android, so the question is: how to include this peace of code in a Phonepap project?.

http://stackoverflow.com/a/18610405

此链接特别提供了一个解决方案phonegap,这对我没有工作,但更重要的给了我如何可以添加自定义android代码在phonegap项目。

This link suggests specifically a solution for phonegap, which did not work for me, but more important gave an idea of how I could add custom android code on a phonegap project.

解决方案

1-在您的phonegap项目中创建以下类(如第一个链接中所示):

1- Create the following class(as indicate in first link) in your phonegap project:



    package com.test.android;

    import android.app.Activity;
    import android.graphics.Rect;
    import android.view.View;
    import android.view.ViewTreeObserver;
    import android.widget.FrameLayout;

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

}


这个类可以放置在你的项目的这个位置:(我不能在这个论坛加载一个图像,我需要至少10个信誉)。在以下网址中查找图片示例:

This class can be placed in this location in your project: (I was not able to load an image in this forum, I need at lease 10 reputation). Find the image sample in this url:

2-每次创建一个phonegap项目,你都会得到一个名为your_project_name.java的类。在我的case是test1.java。编辑类并在方法onCreate中添加以下语句:

2- Any time you create a phonegap project you get a class called your_project_name.java. In my case it is test1.java. Edit the class and add the following sentence in method onCreate:



    AndroidBug5497Workaround.assistActivity(this);

 

您的代码应如下所示:



    public class test1 extends DroidGap
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            // Set by  in config.xml
            super.loadUrl(Config.getStartUrl());
            //super.loadUrl("file:///android_asset/www/index.html")
            AndroidBug5497Workaround.assistActivity(this);
        }
    }
     

解决了我的应用程序中的问题。

3- This fixed the problem in my app.

这篇关于Phonegap - Android如何在软键盘可见时在全屏模式下调整布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆