聚焦editText并打开键盘时如何移动视图?

时间:2018-06-30 21:04:31

标签: java android android-layout android-view android-softkeyboard

我有一个ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".LoginActivity">

<RelativeLayout
    android:id="@+id/login_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:focusableInTouchMode="true"
        android:orientation="vertical">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:layout_margin="55dp"
            android:src="@drawable/sss" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/helvetica_neue_cyr_roman"
            android:padding="4dp"
            android:text="@string/title_email"
            android:textColor="@color/colorWhite"
            android:textSize="14sp" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:errorTextAppearance="@style/ErrorText"
            app:hintEnabled="false"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/colorAccent">

            <AutoCompleteTextView
                android:id="@+id/email"
                android:layout_width="match_parent"
                android:layout_height="46dp"
                android:backgroundTint="@color/colorWhite"
                android:fontFamily="@font/helvetica_neue_cyr_medium"
                android:hint="@string/hint_email"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="@color/colorWhite"
                android:textColorHint="@color/colorHint"
                android:textSize="14sp" />

        </android.support.design.widget.TextInputLayout>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/helvetica_neue_cyr_roman"
            android:padding="4dp"
            android:text="@string/title_password"
            android:textColor="@color/colorWhite"
            android:textSize="14sp" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:errorTextAppearance="@style/ErrorText"
            app:hintEnabled="false"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/colorAccent">

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:backgroundTint="@color/colorWhite"
                android:fontFamily="@font/helvetica_neue_cyr_medium"
                android:hint="@string/hint_password"
                android:imeActionId="6"
                android:imeActionLabel="@string/action_sign_in"
                android:imeOptions="actionUnspecified"
                android:inputType="textPassword"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="@color/colorWhite"
                android:textColorHint="@color/colorHint"
                android:textSize="14sp" />

        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/sign_in_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/button_shape"
            android:fontFamily="@font/helvetica_neue_cyr_medium"
            android:text="@string/action_sign_in"
            android:textAllCaps="false"
            android:textColor="@color/colorWhite"
            android:textSize="16sp" />
    </LinearLayout>
 </RelativeLayout>

我在显示我真正需要的东西时遇到了一些问题。

This is how view looks by default 不可滚动

Clicking on email editText 可滚动

Password editText click 可滚动

And this is the screenshot i want the app to look like

说我的意思是-如果我单击editTexts,则需要我的视图向上移动到相同位置。键盘消失后,我需要将视图转到默认位置。

打开键盘后,我不需要滚动视图。

我一直试图通过添加

来实现这一目标
android:windowSoftInputMode="adjustResize"

android:windowSoftInputMode="adjustPan"

要体现

是否有可能制造?

谢谢。

1 个答案:

答案 0 :(得分:0)

我相信使用正确的布局配置(也许只是约束布局而不是滚动布局?),您可以在点击其中一个字段时以编程方式隐藏queries徽标,并在该字段单击时将徽标带回失去重点。

相关问题