adjustPan 不阻止键盘覆盖 EditText
我正在尝试创建一个非常基本的聊天屏幕,其中包含显示文本的 ListView 和底部的 EditText,以及 EditText 右侧的“发送”按钮。一切功能正常,但是当我单击 EditText 时,虚拟键盘会覆盖它。屏幕稍微平移,但不足以在键盘上方可见。我的清单中有“adjustPan”标签,并且也尝试了“adjustResize”标签但无济于事。我猜这与我的布局设置方式有关,但老实说我不知道。请帮忙!
当前布局...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1"
android:stackFromBottom="true">
</ListView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/sendMessageBox"
android:focusable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"
android:maxLines="4"
android:text=""
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:maxLength="1000"
android:hint="Type your message..."
android:imeOptions="actionSend"/>
<Button android:id="@+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Send"/>
</LinearLayout>
I'm trying to create a pretty basic chat screen with a ListView displaying the text and an EditText at the bottom and a "Send" button to the right of the EditText. Everything is functional, but when I click the EditText, the virtual keyboard covers it. The screen pans up a little but not enough to become visible above the keyboard. I've got the "adjustPan" tag in my manifest and have also tried the "adjustResize" tag to no avail. I'm guessing it has something to do with the way my layout is set up, but I honestly have no clue. Please help!
Current Layout...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1"
android:stackFromBottom="true">
</ListView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/sendMessageBox"
android:focusable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"
android:maxLines="4"
android:text=""
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:maxLength="1000"
android:hint="Type your message..."
android:imeOptions="actionSend"/>
<Button android:id="@+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Send"/>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
经过大量搜索后,显然这就是我所说的错误。如果您使用全屏标签(从活动中删除状态栏),则在不将活动包装在 ScrollView 中的情况下无法使用“调整调整大小”。不幸的是,对我来说,我使用的是 ListView,这会产生另一个问题。我厌倦了搞乱它,可能会放弃该活动的全屏。
After doing a lot of searching apparently it's what I'm calling a bug. If you use the fullscreen tag (to remove the status bar from the activity) you can't use "adjustResize" without wrapping the activity in a ScrollView. Unfortunately for me I'm using a ListView which would create yet another problem. I'm sick of messing with it and will probably just abandon the fullscreen on that activity.
在清单文件中,您需要设置适当的
android:windowSoftInputMode
属性。此属性自 API 3 起有效。选项为: http:// /developer.android.com/guide/topics/manifest/activity-element.html#wsoft
In your manifest file, you need to set the appropriate
android:windowSoftInputMode
property. This attribute is valid since API 3.Options are: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
如果您在清单中为 Activity 设置了 android:windowSoftInputMode="adjustResize",则 ScrollView(或其他可折叠 ViewGroup)将缩小以容纳软键盘。但是,如果您在 Activity 的主题中设置
android:windowFullscreen="true"
,则 ScrollView 不会缩小,因为它被迫填满整个屏幕。但是,在主题中设置android:fitsSystemWindows="false"
也会导致 adjustmentResize 不起作用if you set
android:windowSoftInputMode="adjustResize"
for an activity in the manifest, then a ScrollView (or other collapsable ViewGroups) will shrink to accommodate the soft keyboard. But, if you setandroid:windowFullscreen="true"
in the activity’s theme, then the ScrollView won’t shrink because it’s forced to fill the whole screen. However, settingandroid:fitsSystemWindows="false"
in your theme also causes adjustResize not to work我的 AndroidManifest 中有这个。它导致
adjustPan
停止正常工作。我删除了下面的块,一切又恢复正常了。I had this in my AndroidManifest. It caused the
adjustPan
to stop working correctly. I removed the block below and everything works fine again.这是我找到的一种解决方法。打开有问题的 editText 并按 RETURN 键。请注意,它将 editText 移动到更靠近您要拍摄的位置。
因此,虽然很hacky,但您基本上可以在编辑文本的顶部添加换行符。
这似乎也可以在底部使用换行符,但您必须使用延迟才能添加换行符,直到软键盘动画到位后。
请注意,我仅在某些手机 (DroidX) 上遇到此问题。
Here is one workaround I have found. Open the problematic editText and hit the RETURN key. Notice it shifts the editText closer to the position you're shooting for.
So although hacky, you can essentially please a newline at the top of the edittext.
This also seems to work using a newline at the bottom but you'd have to use a delay to not add the newline until AFTER the soft keyboard has animated into position.
Note I only have this problem on certain phones (DroidX).
尝试在清单中添加
android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden"
。Try adding
android:windowSoftInputMode="adjustResize|stateVisible|stateAlwaysHidden"
in your manifest.您可以尝试以下设置:
You can try the following settings: