0

我在布局中做了一个标志,如下所示:

在此处输入图像描述

xml如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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="match_parent"
    android:background="@color/colorWhite"
    android:fillViewport="true"
    tools:context=".SignInActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="1">

    <ImageView
        android:id="@+id/image_signin"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:layout_marginEnd="8dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/img_signin"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.2"
        app:layout_constraintHorizontal_bias="0.55"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.48"/>

    <TextView
        android:id="@+id/text_sign_in"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:layout_marginTop="60dp"
        android:fontFamily="@font/assistant_semibold"
        android:text="Sign In"
        android:textColor="@color/colorLightPurple"
        android:textSize="24dp"
        app:layout_constraintHeight_percent="0.05"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/image_signin"
        app:layout_constraintWidth_percent="0.3" />

    <EditText
        android:id="@+id/et_sign_in_email"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="36dp"
        android:drawablePadding="10dp"
        android:textColor="@color/colorBlackText"
        android:background="@drawable/btn_underline"
        android:drawableStart="@drawable/ic_mail_outline_black_24dp"
        android:drawableLeft="@drawable/ic_mail_outline_black_24dp"
        android:fontFamily="@font/assistant_semibold"
        android:hint="E-mail"
        app:layout_constraintHeight_percent="0.06"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_sign_in"/>

    <EditText
        android:id="@+id/et_sign_in_password"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="20dp"
        android:drawablePadding="10dp"
        android:textColor="@color/colorBlackText"
        android:background="@drawable/btn_underline"
        android:drawableStart="@drawable/ic_lock_outline_black_24dp"
        android:drawableLeft="@drawable/ic_lock_outline_black_24dp"
        android:fontFamily="@font/assistant_semibold"
        android:hint="Password"
        android:inputType="textPassword"
        app:layout_constraintHeight_percent="0.06"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et_sign_in_email"/>

    <Button
        android:id="@+id/button_sign_in"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="40dp"
        app:layout_constraintHeight_percent="0.08"
        app:layout_constraintTop_toBottomOf="@+id/et_sign_in_password"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:background="@drawable/btn_rounded_purple"
        android:fontFamily="@font/assistant"
        android:text="Sign In"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textSize="20dp"/>

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

当我输入电子邮件/密码时,键盘会隐藏登录按钮,因此我将其添加到清单android:windowSoftInputMode="adjustResize"中。

结果如下:

在此处输入图像描述

有没有办法让我的布局中的对象始终保持相同的大小,并且只是将整个布局推到键盘上方?

我专门在里面做了整个布局,ScrollView所以它可以移动,但问题是键盘不是“屏幕的一部分”,从我的理解来看,它更像是一个浮动,所以它不会移动布局。

谢谢

4

1 回答 1

0

您可以使用约束布局:

    <androidx.constraintlayout.widget.ConstraintLayout
     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:id="@+id/constraint_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true">

        <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:src="@drawable/image"
        app:layout_constraintBottom_toTopOf="@+id/username"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

        <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
        ...
    </androidx.constraintlayout.widget.ConstraintLayout>
于 2019-09-30T20:07:36.600 回答