java 出现键盘时android调整布局
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11416263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android resize layout when keyboard appears
提问by Jaume
I would like to reposition layout when keyboard appears, for example when editing a text field, in order to get visibility on focused field. I tried windowSoftInputMode but I cannot get any difference. How to reach it? Thank you.
我想在键盘出现时重新定位布局,例如在编辑文本字段时,以便获得焦点字段的可见性。我试过 windowSoftInputMode 但我没有任何区别。如何达到?谢谢你。
<activity
android:name="com.xxxx.projecte1.TabBar_Activity"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
/>
采纳答案by Angelo
I believe the problem is this line
我相信问题是这条线
android:configChanges="keyboardHidden|orientation|screenSize"
android:configChanges="keyboardHidden|orientation|screenSize"
in your code. This line tells the Android
that your Activity
will handle this 3 events on its own. If you remove this line, i believe you will have the desired effect.
在你的代码中。此行告诉Android
您Activity
将自行处理这 3 个事件。如果你去掉这行,我相信你会有想要的效果。
See herefor the configChanges
attribute.
见这里的configChanges
属性。
回答by wadali
<activity
android:name=".WActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode"
android:icon="@drawable/navigation_two"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/appTheme"
android:windowSoftInputMode="adjustResize" />
回答by Levite
For anyone else who might have a similar problem:
对于可能有类似问题的其他人:
What fixed it in my case was just putting
在我的情况下修复它的只是把
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
into my activity's onCreate
method.
进入我的活动onCreate
方法。
Without any xml changes whatsoever, since those did not work for me whatsoever, but this worked right away like a charm. Although an xml solution seems nicer to me, even the same parameter did not work.
没有任何 xml 更改,因为它们对我没有任何作用,但这就像一个魅力一样。尽管 xml 解决方案对我来说似乎更好,但即使是相同的参数也不起作用。
Sharing it since I did not find a quick and easy fix myself online.
分享它,因为我没有在网上找到快速简便的修复方法。