Android - 软键盘将我的活动布局推出屏幕
我的活动布局如下所示。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout android:id="@+id/title_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:background="@drawable/bg_title" />
<LinearLayout android:id="@+id/main"
android:width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip" >
<EditText android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some search terms"
android:singleLine="true"
android:layout_weight="1" />
<Button android:id="@+id/btn_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_hide"
android:layout_marginLeft="6dip" />
</LinearLayout>
</LinearLayout>
因此,搜索框固定在屏幕底部。
但是,当用户单击 EditText 时,软键盘会显示并将布局推出屏幕(搜索框除外)。
我刚刚开始使用 Android,所以我在这里做错了什么吗?
My activity's layout is as shown below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout android:id="@+id/title_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:background="@drawable/bg_title" />
<LinearLayout android:id="@+id/main"
android:width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip" >
<EditText android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some search terms"
android:singleLine="true"
android:layout_weight="1" />
<Button android:id="@+id/btn_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_hide"
android:layout_marginLeft="6dip" />
</LinearLayout>
</LinearLayout>
So, the search box is fixed to the bottom of the screen.
But, when user clicks the EditText, Soft Keyboard shows up and pushes the layout out of the screen except the search box.
I'm just starting out with Android, so am I doing anything wrong here??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在清单中为您的活动添加以下内容:
Try adding the following for your activity in Manifest:
对于那些感兴趣的人,
android:windowSoftInputMode="adjustPan"
和android:windowSoftInputMode="adjustResize"
之间的区别:"adjustResize"
活动窗口的大小已调整,以便为屏幕上的软键盘腾出空间。
“adjustPan”
Activity 窗口的内容会自动平移,以便当前焦点永远不会被键盘遮挡。这样用户就可以看到他们正在输入的内容。这通常比调整大小更不理想,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。
Android 文档
引用的链接
For those that are interested, the difference between
android:windowSoftInputMode="adjustPan"
andandroid:windowSoftInputMode="adjustResize"
:"adjustResize"
The activity's window is resized to make room for the soft keyboard on screen.
"adjustPan"
The contents of the activity's window are automatically panned so that the current focus is never blocked by the keyboard. This is so the user can see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
Android Documentation
Cited link
@Raj如果您正在使用选项卡式应用程序,则必须在要添加选项卡的
Activity
上添加android:windowSoftInputMode="adjustPan"
,这很可能是您的启动器活动。
这是我的代码片段
@Raj If you are working with a tabbed application you have to add
android:windowSoftInputMode="adjustPan"
on the
Activity
where you are adding the tabs, this would most probably be your launcher activity.Here is a snippet from my code