为什么EditText被软键盘遮挡?

4

我有一个在ScrollView之外的图片和多个EditText在同一个滚动视图中,但是当点击某个EditText并打开键盘时,图片视图的大小会改变,而我不想改变它的大小,因此我在清单文件中的活动中添加了 android:windowSoftInputMode="adjustResize|adjustPan|stateVisible"。现在当键盘打开时,最后一个EditText隐藏在键盘后面,并且滚动视图没有滚动到最后。

xml:
<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar_without_elevation" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25"
    android:background="@color/primary_color"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="@dimen/size_0_dp"
        android:layout_height="match_parent"
        android:layout_weight="0.3" />

    <com.balysv.materialripple.MaterialRippleLayout
        android:id="@+id/rippleChangeProfileImage"
        style="@style/ImageViewRipple"
        android:layout_width="@dimen/size_0_dp"
        android:layout_height="match_parent"
        android:layout_weight="0.4"
        android:gravity="center">

        <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/imgProfile"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:layout_margin="@dimen/size_8_dp"
            android:background="@drawable/ic_add_a_photo_white_48dp"
            android:onClick="changeContactPhoto"
            app:civ_border_color="#ffffff"
            app:civ_border_width="2dp" />
    </com.balysv.materialripple.MaterialRippleLayout>

    <TextView
        android:layout_width="@dimen/size_0_dp"
        android:layout_height="match_parent"
        android:layout_weight="0.3" />
</LinearLayout>

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.75"
    android:fillViewport="true"
    android:isScrollContainer="false"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--android:layout_weight="1"-->


        <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/size_10_dp"
            android:gravity="center"
            android:orientation="vertical">
            <!--android:layout_marginTop="@dimen/size_10_dp"-->

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/linearName"
                style="@style/ProfileLinearLayout"
                android:layout_marginBottom="@dimen/size_5_dp">

                <com.rengwuxian.materialedittext.MaterialEditText
                    android:id="@+id/edtName"
                    style="@style/profileDialogEditText"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/size_16_dp"
                    android:layout_marginRight="@dimen/size_16_dp"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:paddingRight="@dimen/size_10_dp"
                    android:singleLine="true"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@color/Profile_text_color"
                    android:textSize="@dimen/size_12_sp"
                    app:met_floatingLabel="normal"
                    android:windowSoftInputMode="adjustResize" />

                <ImageView
                    android:id="@+id/imgName"
                    android:layout_width="32dp"
                    android:layout_height="32dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="@dimen/size_15_dp"
                    android:src="@drawable/ic_person_outline_white_24dp" />
            </LinearLayout>

            <ImageView
                android:id="@+id/imageView13"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/size_5_dp"
                android:src="@drawable/item_separator_as_line" />

    //several EditText Like This

        </LinearLayout>

`


请在此处发布您的代码。 - Stanojkovic
你的清单文件中的AppTheme是什么API? - Stanojkovic
Theme.AppCompat.Light.NoActionBar - Mohammad Tazehkar
你的API级别是多少? - Stanojkovic
minSdkVersion 15 targetSdkVersion 22 - Mohammad Tazehkar
2个回答

2
尝试从主线性布局中移除您的重量,这应该有效; 并将屏幕宽度或高度设置为您的LinearLayout。

0

在你的 <activity> 中添加以下内容:

android:windowSoftInputMode="adjustPan" 

或者:

android:windowSoftInputMode="adjustResize" 

像这样:

<activity
    android:name="com.my.MainActivity"
    android:screenOrientation="portrait"
    android:label="@string/title_activity_main"
    android:windowSoftInputMode="stateVisible|adjustResize" >
</activity>

谢谢回答,但我已将其添加到所有EditText,并从清单中删除了android:windowSoftInputMode,现在所有页面都可以滚动,我不想要超出ScrollView的图像。 - Mohammad Tazehkar
我看到了这篇文章http://android-developers.blogspot.rs/2009/04/updating-applications-for-on-screen.html - Stanojkovic
当软键盘打开时,图像视图的大小会发生变化。我希望图像视图的大小保持不变。 - Mohammad Tazehkar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接