出现键盘时调整布局大小(ScrollView) [英] Layout Resize when keyboard appear (ScrollView)
问题描述
我想在出现键盘时将屏幕尺寸保持在Layout
中,我的想法是在两种情况下(带或不带键盘)都获得下一个:
I want to maintain the screen size in Layout
when the keyboard appears, my idea is obtain the next in both cases (with or without keyboard):
|-----------------|
| image |
| |
|-----------------|
| |
| center lay |
| |
|-----------------|
| |
| image |
|-----------------|
但是在中心布局中,我有一些EditText
,当出现软键盘时,中心布局会减小其高度,并且会变短,从而导致第一个EditText
粘在上面的图片上.我尝试了几种形式,例如使用RelativeLayout
对齐图像的顶部和底部,但是当键盘出现时,隐藏了中心布局并造成了可怕的效果.
But in the center layout I have some EditText
and when the soft KeyBoard appear, the center layout reduce its height and is shorter, causing the first EditText
sticking to the picture above. I tried several forms, for example with a RelativeLayout
align the images at the top and bottom, but when the keyboard appears hide the center layout and causes a horrible effect.
这是我的代码,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/login_iv_points_top"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_gravity="top"
android:src="@drawable/image" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<EditText
android:id="@+id/login_et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/login_edit_margin_left"
android:layout_marginRight="@dimen/login_edit_margin_right"
android:ems="10"
android:hint="@string/login_et_email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/login_et_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/login_edit_margin_left"
android:layout_marginRight="@dimen/login_edit_margin_right"
android:layout_marginTop="@dimen/login_edit_pass_margin_top"
android:ems="10"
android:hint="@string/login_et_pass"
android:inputType="textPassword" />
<Button
android:id="@+id/login_bt_login"
android:layout_width="match_parent"
android:layout_height="@dimen/login_button_height"
android:layout_marginLeft="@dimen/login_button_margin_left"
android:layout_marginRight="@dimen/login_button_margin_right"
android:layout_marginTop="@dimen/login_button_margin_top"
android:background="@drawable/bt_selectable_degraded_style"
android:text="@string/login_bt_access"
android:textColor="@color/bt_text_color" />
<TextView
android:id="@+id/login_tv_forgot_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/login_forgot_margin_top"
android:linksClickable="true"
android:onClick="registerForgotClick"
android:text="@string/login_tv_forgot_pass"
android:textColorLink="@color/company_color" />
</LinearLayout>
<ImageView
android:id="@+id/login_iv_points_bottom"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:src="@drawable/image" />
</LinearLayout>
</ScrollView>
推荐答案
也许您可以尝试将android:windowSoftInputMode="adjustNothing"
放在Android Manifest的活动节点上.然后,键盘将弹出内容.
Maybe you can try to put android:windowSoftInputMode="adjustNothing"
on the activity node of your Android Manifest. The keyboard will then pop over the content.
这篇关于出现键盘时调整布局大小(ScrollView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!