出现软键盘时如何调整布局 [英] How to adjust layout when soft keyboard appears
本文介绍了出现软键盘时如何调整布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在软键盘激活时调整/重新调整布局大小,如下:
I would like to adjust/re-size the layout when the soft-keyboard activated, as below:
之前和之后:
在 SO 中找到了几个资源:
Found couple resources in SO:
<小时>
但是问题&答案相当模棱两可,这里的问题更清楚地说明了我想要什么.
But the questions & answers are rather ambiguous, here's the question with clearer picture of what I want.
要求:
- 它应该适用于任何屏幕尺寸的手机.
- 注意到FACEBOOK"和Sign Up forFacebook"前后都发生了变化.
- 不涉及滚动视图.
推荐答案
只需添加
android:windowSoftInputMode="adjustResize"
在您声明此特定活动的 AndroidManifest.xml 中,这将调整布局调整大小选项.
in your AndroidManifest.xml where you declare this particular activity and this will adjust the layout resize option.
下面是一些布局设计的源代码
some source code below for layout design
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="FaceBook"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="username" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="password" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="20dp"
android:text="Log In" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="17dp"
android:gravity="center"
android:text="Sign up for facebook"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
这篇关于出现软键盘时如何调整布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文