简体   繁体   English

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

[英]How to move view when editText is focused and keyboard is open?

I have a ScrollView 我有一个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>

And i have some issues with showing what i exactly need. 我在显示我真正需要的东西时遇到了一些问题。

This is how view looks by default not scrollable 这是视图默认情况下 不可滚动的方式

Clicking on email editText scrollable 单击电子邮件editText 可滚动

Password editText click scrollable 密码editText单击 可滚动

And this is the screenshot i want the app to look like 这是我希望应用程序看起来像的屏幕截图

By saying that i mean - i need my view to move upper to the same position if i click on editTexts. 我的意思是-如果我单击editTexts,则需要我的视图向上移动到相同位置。 And after keyboard disappears i need view to come to default position. 键盘消失后,我需要查看到默认位置。

I dont need to scroll view after keyboard is open. 打开键盘后,无需滚动视图。

I've been trying to make that happen with adding 我一直在尝试通过添加来实现这一目标

android:windowSoftInputMode="adjustResize"

and

android:windowSoftInputMode="adjustPan"

to manifest 体现

Is it even possible to make? 甚至有可能做到吗?

Thank you. 谢谢。

我相信使用正确的布局配置(也许只是约束布局而不是滚动?),您可以使用Visibility.GONE隐藏徽标。单击某个字段时,可以通过编程方式将GONE隐藏;当该字段失去焦点时,可以将徽标重新显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 聚焦edittext时如何显示软键盘 - How to show soft-keyboard when edittext is focused 如何在焦点 EditText 之外单击时隐藏软键盘,但如果单击另一个 EditText 则不隐藏? - How to make the soft keyboard hide when clicked outside of the focused EditText BUT not if another EditText is clicked? 焦点时如何将EditText移到顶部? - android - How to shift EditText to top when focused? 聚焦EditText时如何隐藏IME - How to hide IME when EditText is focused 创建Activity时如何使EditText不聚焦 - How to make EditText not focused when creating Activity 专注于editText时只需打开英文键盘 - Just open keyboard English when focus on editText 使用打开的键盘无法看到EditText - EditText Is Not Visible With Open Keyboard 单击fab时将EditText(或布局)移动到键盘上方 - Move EditText (or a layout) above the keyboard when you click a fab 回收器视图在键盘打开时向上隐藏消息/如何在键盘打开时防止回收器视图滚动 - recycler view hides message upward when keyboard is open / how to keep recycler View from scrolling when keyboard is on 在循环器视图中切换到下一个EditText时,如何保持软键盘的连接? - How can I keep the soft keyboard up when switching to the next EditText in a recycler view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM