0

我想在Layout键盘出现时保持屏幕大小,我的想法是在两种情况下(有或没有键盘)都获得下一个:

|-----------------|
| 图片 |
| |
|-----------------|
| |
| 居中|
| |
|-----------------|
| |
| 图片 |
|-----------------|

但是在中心布局中我有一些EditText,当软键盘出现时,中心布局降低了它的高度并且变短了,导致第一个EditText粘在上面的图片上。我尝试了几种形式,例如RelativeLayout在顶部和底部对齐图像,但是当键盘出现时隐藏中心布局并导致可怕的效果。

这是我现在的代码,

<?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>
4

3 回答 3

2

也许你可以尝试把android:windowSoftInputMode="adjustNothing"你的 Android Manifest 的活动节点放在上面。然后键盘将弹出内容。

于 2013-06-07T08:29:37.330 回答
0

尝试在清单文件中的活动中使用它:

android:configChanges="keyboardHidden|orientation"
android:windowSoftInputMode="adjustPan"
于 2013-06-07T08:56:42.453 回答
0

如果您将从清单中删除 windowSoftInputMode,您将失去滚动,因此如果您有一个静态图像,我的意思是来自可绘制资源,而不是尝试这个 getWindow().setBackgroundDrawableResource(R.drawable.ic_launcher);

于 2015-05-21T07:05:40.077 回答