布局屏幕向上移动时,键盘显示
让说我有以下布局:布局屏幕向上移动时,键盘显示
http://i47.tinypic.com/2vchnih.png
,当我在编辑文本单击底部的我得到这个:
http://i45.tinypic.com/352lym9.png
正如您可以注意到,从顶部的图像上移,整个布局移动。 这是我对这个布局XML:
<?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>
而且我也设置这个清单文件,该活动:
android:windowSoftInputMode="adjustPan"
那么,有没有办法从移动时键盘停止我的布局被展示? 谢谢!!!!
好,我没有提到我的应用程序的清单中的任何“windowSoftInputMode”,并运行良好。键盘打开时屏幕不会向上移动。尝试这种方法 - 只需从清单中删除“windowSoftInputMode”参数即可。
试试这个:
android:windowSoftInputMode="adjustNothing"
虽然这段代码片段是受欢迎的,并且可能会提供一些帮助,但如果包含* how *和* why *的解释](// meta.stackexchange.com/q/114762)问题。请记住,你正在为将来的读者回答这个问题,而不仅仅是现在问的人!请编辑您的答案以添加解释,并指出适用的限制和假设。 – 2017-04-04 14:32:09
我的EditText保持动起来为好。
添加重力编辑文本似乎解决了问题。 键盘正在推动我的EditText,所以我将重力添加到XML中编辑文本的底部。
android:gravity=bottom
我已经有了一个windowsoftInputMode,以防止打开键盘,所以只需添加注释代码
机器人:windowSoftInputMode = “stateHidden | adjustPan | adjustResize”
检查此链接: http://stackoverflow.com/questions/9989130/page-scroll-when-soft-keyboard-poped-up – 2012-07-10 09:26:31
我认为这个链接会帮助你。 [链接] [1] [1]:http://stackoverflow.com/questions/5516216/how-to-avoid-soft-keyboard-pushing-up-my-layout 谢谢... – user4232 2012-07-10 09:27:19
@YogeshSomani没有什么在那里我还没有试过。它不工作 – adrian 2012-07-10 09:32:13