android:WindowsofInputMode=";“调整大小”;不';没什么区别吗?

android:WindowsofInputMode=";“调整大小”;不';没什么区别吗?,android,android-layout,android-keypad,android-input-method,Android,Android Layout,Android Keypad,Android Input Method,我有一个使用此布局的人造对话框: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"

我有一个使用此布局的人造对话框:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout    xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:id="@+id/containerPageConatiner">

    <FrameLayout    android:id="@+id/dialogHolder"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:padding="15dp"
                    android:layout_gravity="center"
                    android:background="@drawable/panel_picture_frame_bg_focus_blue"/>    
</FrameLayout> 
EDIT2

Scrollview作为父项也没有帮助:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/containerPageConatiner"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
            android:id="@+id/dialogHolder"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="15dp" />

</ScrollView>

问题似乎出在FrameLayout上,因为它的行为方式是,每个子对象占用该框架的可见空间,因此不需要调整大小以适合子对象。
尝试使用RelativeLayout。它应该可以工作。

试着把你的
线性布局
放在一个
滚动视图
上,这对我来说曾经很有用。

我创建了一个新项目,试图让窗口大小调整的基本功能发挥作用,然后慢慢地将它移到我项目的目标位置。通过这样做,我将问题追溯到:

在我的主题层次结构中,我有以下属性:

<item name="android:windowFullscreen">true</item> 
true
它隐藏在
主题.Black.NoTitleBar.FullScreen
的层次上,这是我自定义主题的祖先

建议这是一个“指示此窗口是否应填充整个屏幕的标志”。如果你有一个占据整个屏幕的应用程序,这听起来是件好事。。。但它仍然占据了整个屏幕,没有国旗


事实上,一旦你把它拿出来,应用程序就完全没有任何变化。。。除了
调整大小
现在可以完美地工作。

当将全屏标志分配给活动时,原始海报发现android:windowFullscreen属性将不起作用,因此当软键盘可见且不可滚动时,您的窗口将不会调整大小


只需删除全屏标志而不使用全屏主题,当软键盘可见时,即可进行滚动。

不久前,我在创建的库中也遇到了同样的问题。()

就我所见,所有提供的答案都不能解决主要问题,它们只是指向删除全屏标志(
android:windowFullscreen
),这对许多人来说都不是解决方案

上述“问题”只出现在API级别为19(KITKAT)的Android版本中,因为它们改变了行为。正确地说,这不是问题,它正在按预期工作。请参阅Android员工的评论()


因此,我开始研究Android源代码,并通过使用
ViewTreeObserver.OnGlobalLayoutListener
找到以下解决方案,并在键盘显示/隐藏时做出反应。如果显示键盘,我会将填充添加到容器视图的底部,然后模拟与
adjustResize
相同的操作


解决方案 为了简化使用,我将整个过程包装在一个简单的KeyboardUtil助手类中

/**
 * Created by mikepenz on 14.03.15.
 * This class implements a hack to change the layout padding on bottom if the keyboard is shown
 * to allow long lists with editTextViews
 * Basic idea for this solution found here: http://stackoverflow.com/a/9108219/325479
 */
public class KeyboardUtil {
    private View decorView;
    private View contentView;

    public KeyboardUtil(Activity act, View contentView) {
        this.decorView = act.getWindow().getDecorView();
        this.contentView = contentView;

        //only required on newer android versions. it was working on API level 19 (Build.VERSION_CODES.KITKAT)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
        }
    }

    public void enable() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
        }
    }

    public void disable() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
        }
    }


    //a small helper to allow showing the editText focus
    ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            //r will be populated with the coordinates of your view that area still visible.
            decorView.getWindowVisibleDisplayFrame(r);

            //get screen height and calculate the difference with the useable area from the r
            int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels;
            int diff = height - r.bottom;

            //if it could be a keyboard add the padding to the view
            if (diff != 0) {
                // if the use-able screen height differs from the total screen height we assume that it shows a keyboard now
                //check if the padding is 0 (if yes set the padding for the keyboard)
                if (contentView.getPaddingBottom() != diff) {
                    //set the padding of the contentView for the keyboard
                    contentView.setPadding(0, 0, 0, diff);
                }
            } else {
                //check if the padding is != 0 (if yes reset the padding)
                if (contentView.getPaddingBottom() != 0) {
                    //reset the padding of the contentView
                    contentView.setPadding(0, 0, 0, 0);
                }
            }
        }
    };


    /**
     * Helper to hide the keyboard
     *
     * @param act
     */
    public static void hideKeyboard(Activity act) {
        if (act != null && act.getCurrentFocus() != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
        }
    }
}

然后,您可以通过执行以下操作在活动或片段中使用它:

//initialize the KeyboardUtil (you can do this global)
KeyboardUtil keyboardUtil = new KeyboardUtil(activity, getContent().getChildAt(0));

//enable it
keyboardUtil.enable();

//disable it
keyboardUtil.disable();

上面提到的库中使用了整个util类,可以在这里找到。这将始终包含最新版本。(如果有改进)

确保在样式中将
WindowTransparcentStatus
设置为
false

没有使用
滚动视图作为我的父视图,我刚刚将
android:fitsSystemWindows=“true”
添加到我的父视图中(这是一个
相对视图
)并将调整大小调整为活动的清单,它就起作用了。

我必须设置

<item name="android:windowFullscreen">false</item> 
false

尽管如此,我从未将其设置为true,并且应用程序实际上不是全屏。

我不知道为什么,但如果您的主题中有
true
,请将其更改为
false
。它将开始工作。真的很奇怪。

用RelativeLayout代替FrameLayout也有同样的问题。正如您从编辑线布局中看到的那样,也没有任何帮助。尝试将android:fillViewport=“true”添加到ScrollView+1 frameLayout无法很好地使用android:WindowsOfInputMode=“adjustResize”,将视图移到frameLayout之外修复了此问题。这只是在4.0.4上不起作用,但是使用一个EditText进行检查。在edittect内单击以显示软键盘,现在您可以看到此android的用法:windowSoftInputMode=“adjustResize”。您是否使用adjustNothing?即使键盘显示您的布局也不应得到任何更改。对不起,我不理解您的意思。即使使用滚动视图作为父视图,在对话框中单击编辑文本也不会调整屏幕的任何部分。谢谢您的帖子!但我希望全屏显示并调整大小:(重新阅读答案。无论
windowFullscreen
是否设置为true、false或不存在,您的活动仍将全屏显示。好的。我想我的问题是,我没有自己的主题。它的工作原理就像您使用自己的主题编写一样。:)当我从自定义主题中删除android:windowFullscreen时,不幸的是,它停止全屏显示(OS4.1)。你能发布你的主题的完整代码吗?也许我的实现中缺少了一些东西。我将添加我的观察结果。格雷姆对android:windowFullscreen属性的看法是正确的。它隐藏了状态栏(顶部有时钟和通知等)。其结果是,在adjustResize设置的属性android:WindowsOfInputMode无法按预期工作。当显示软键盘时,该活动占用所有可用空间,并且不知道软键盘占用了部分空间。因此,无法滚动到“活动”的底部。注释的73只是说明这是我设备上的dp。你不必设置这个或任何东西。我只保留初始高度以防止检测问题在使用不同主题的应用程序中,您可能希望在应用修复之前查询当前窗口是否设置了
WindowManager.LayoutParams.FLAG_半透明_状态
FLAG_半透明_导航
。修正了我遇到的一个问题。如果屏幕上有一个数字字段和一个字母字段,就会产生一个有趣的效果。首先单击数字字段可正确调整屏幕,然后单击
//initialize the KeyboardUtil (you can do this global)
KeyboardUtil keyboardUtil = new KeyboardUtil(activity, getContent().getChildAt(0));

//enable it
keyboardUtil.enable();

//disable it
keyboardUtil.disable();
<item name="android:windowFullscreen">false</item>