显示键盘时屏幕布局向上移动 [英] layout of the screen moves up when keyboard is displayed

查看:33
本文介绍了显示键盘时屏幕布局向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下布局:

当我点击底部的编辑文本时,我得到了这个:

when I click on the edit text at the bottom I get this:

如您所见,顶部的图像向上移动,整个布局移动.这是我用于此布局的 xml:

As you can notice the image from the top goes upper and the whole layout moves. This is my xml for this layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="#FFFFFF" >

   <LinearLayout
       android:id="@+id/header"
       android:layout_width="fill_parent"
       android:layout_height="75dp"
       android:layout_alignParentLeft="true"
       android:layout_alignParentRight="true"
       android:layout_alignParentTop="true"        
       android:isScrollContainer="true"
       android:background="@drawable/header" >
   </LinearLayout>

   <ScrollView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:id="@+id/scrollauthentication"
       android:layout_below="@+id/header"
       android:background="#FFFFFF"
       android:fillViewport="true" >

       <RelativeLayout
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:background="#FFFFFF" 
           android:id="@+id/authenticationrelativelayout">

           <TextView
               android:id="@+id/login"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignParentLeft="true"
               android:layout_below="@+id/header"
               android:layout_marginLeft="30dp"
               android:layout_marginTop="20dp"
               android:text="login"
               android:textAppearance="?android:attr/textAppearanceMedium"
               android:textColor="@color/lighter_orange"
               android:textSize="28dp" />

           <TextView
               android:id="@+id/usernameTextView"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignLeft="@+id/login"
               android:layout_below="@+id/login"
               android:layout_marginTop="16dp"
               android:text="username"
               android:textAppearance="?android:attr/textAppearanceMedium"
               android:textColor="@color/dark_gray" />

           <EditText
               android:id="@+id/user"
               android:layout_width="260dp"
               android:layout_height="42dp"
               android:layout_alignLeft="@+id/usernameTextView"
               android:layout_below="@+id/usernameTextView"
               android:background="@drawable/edittext_selector"
               android:imeOptions="actionDone"
               android:lines="1"
               android:paddingLeft="10dp" />

           <TextView
               android:id="@+id/passwordTextView"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignLeft="@+id/user"
               android:layout_below="@+id/user"
               android:text="password"
               android:textAppearance="?android:attr/textAppearanceMedium"
               android:textColor="@color/dark_gray" />

           <EditText
               android:id="@+id/password"
               android:layout_width="260dp"
               android:layout_height="42dp"
               android:layout_alignLeft="@+id/passwordTextView"
               android:layout_below="@+id/passwordTextView"
               android:background="@drawable/edittext_selector"
               android:imeOptions="actionDone"
               android:inputType="textPassword"
               android:lines="1"
               android:paddingLeft="10dp" >

               <requestFocus />
           </EditText>

           <CheckBox
               android:id="@+id/remembercheckBox"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignLeft="@+id/password"
               android:layout_below="@+id/password"
               android:layout_marginTop="37dp"
               android:button="@drawable/checkbox_selector"
               android:focusable="true" />

           <TextView
               android:id="@+id/rememberText"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_alignBaseline="@+id/remembercheckBox"
               android:layout_alignBottom="@+id/remembercheckBox"
               android:layout_toRightOf="@+id/remembercheckBox"
               android:text="Remember me"
               android:textAppearance="?android:attr/textAppearanceMedium"
               android:textColor="@color/dark_gray" />
       </RelativeLayout>
   </ScrollView>

   <LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_marginLeft="30dp"
       android:layout_below="@+id/scrollauthentication"
       android:orientation="horizontal" >

       <Button
           android:id="@+id/loginButton"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:background="@color/button_selected"
           android:text="log in"
           android:textColor="@drawable/textblack_selected"
           android:textStyle="bold" >
       </Button>

       <Button
           android:id="@+id/forgotten"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginLeft="10dp"
           android:background="@color/button_selected"
           android:text="forgotten password"
           android:textColor="@drawable/textblack_selected"
           android:textStyle="bold" />
   </LinearLayout>

</RelativeLayout>

而且我还在此活动的清单文件中设置了它:

And I have also set this in manifest file for this activity:

android:windowSoftInputMode="adjustPan"

那么有没有办法在显示键盘时阻止我的布局移动?谢谢!!!!

So is there a way to stop my layout from moving when the keyboard is displayed? Thank you!!!!

推荐答案

好吧,我没有在我的应用清单中提到任何windowSoftInputMode",它运行良好.键盘打开时屏幕不向上移动.试试这个方法 - 只需从清单中删除windowSoftInputMode"参数.

well, I have not mentioned any "windowSoftInputMode" in my app's manifest and it runs fine. Screen does not move up when the keyboard opens up. Try this approach - just remove the "windowSoftInputMode" parameter from your manifest .

这篇关于显示键盘时屏幕布局向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆