PhoneGap的 - 机器人如何调整在全屏模式下布局时softkeyboard可见全屏、机器人、布局、模式下

2023-09-05 09:44:57 作者:苡为会緈幅

我工作的三星Galaxy Tab 3的PhoneGap的应用程序,当该应用程序是在全屏模式下,softkeyboard隐藏的文本输入框,它是不可能的,滚动页面看到的内容。我怎么能解决这个问题?

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的工作经验,所以问题是:?如何将之纳入和平code在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的,这并没有为我工作的解决方案,但更重要的给了我怎么能对一个的PhoneGap项目中添加定制的Andr​​oid code的想法。

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声望)。发现在这个URL中的图像样本:

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 - 你创建你得到一个类your_project_name.java一个的PhoneGap项目的任何时间。在我的情况下,它是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);

 

您code应该是这样的:

Your code should look like 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这解决了这一问题在我的应用程序。

3- This fixed the problem in my app.