Android Layout - предотвращение сжатия макета, когда клавиатура скрыта - PullRequest
1 голос
/ 20 марта 2019

Есть ли способ предотвратить изменение размера макета при исчезновении клавиатуры. Когда клавиатура видна, раскладка растягивается, как и ожидалось, добавляя android:windowSoftInputMode="adjustResize|stateAlwaysVisible" проявить. Но когда клавиатура скрыта, раскладка настраивается с учетом всей высоты устройства. Есть ли способ, чтобы сохранить размер макета, когда клавиатура скрыта. Или способ рассчитать высоту клавиатуры и отрегулировать высоту относительного расположения с учетом высоты клавиатуры.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rlAtmFragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true"
    android:paddingStart="@dimen/thirty_two_dp"
    android:paddingEnd="@dimen/thirty_two_dp">

    <WTextView
        android:id="@+id/tvEnterYourPin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/thirty_two_dp"
        android:layout_marginBottom="@dimen/eight_dp"
        android:text="@string/biometric_please_enter_your_pin"
        android:textColor="@color/black"
        android:textSize="@dimen/nineteen_sp"
        app:WTextView_font="bold" />


    <WTextView
        android:id="@+id/tvCardNumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvEnterYourPin"
        android:alpha="0.5"
        android:lineSpacingExtra="0.14sp"
        android:lineSpacingMultiplier="1.40"
        android:text="@string/biometric_please_card_number"
        android:textColor="@color/offer_title"
        android:textSize="@dimen/fifteen_sp"
        app:WTextView_font="myriadpro_regular" />

    <LinearLayout
        android:id="@+id/llPinCodeContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:layout_marginTop="0dp"
        android:background="@color/white"
        android:gravity="center|center_vertical"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/ivPin1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/fifteen_dp"
            android:contentDescription="@string/app_label"
            app:srcCompat="@drawable/pin_empty" />

        <ImageView
            android:id="@+id/ivPin2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/fifteen_dp"
            android:contentDescription="@string/app_label"
            app:srcCompat="@drawable/pin_empty" />

        <ImageView
            android:id="@+id/ivPin3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/fifteen_dp"
            android:contentDescription="@string/app_label"
            app:srcCompat="@drawable/pin_empty" />

        <ImageView
            android:id="@+id/ivPin4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/fifteen_dp"
            android:contentDescription="@string/app_label"
            app:srcCompat="@drawable/pin_empty" />

        <ImageView
            android:id="@+id/ivPin5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_label"
            android:visibility="visible"
            app:srcCompat="@drawable/pin_empty" />

    </LinearLayout>

    <ProgressBar
        android:id="@+id/pbEnterAtmPin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/llPinCodeContainer"
        android:layout_gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/sixteen_dp"
        android:indeterminateTint="@color/black"
        android:visibility="invisible" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="@dimen/twenty_four_dp">

        <TextView
            android:id="@+id/tvForgotPin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_centerInParent="true"
            android:gravity="start"
            android:text="@string/biometric_forgot_atm_pin_code"
            android:textColor="@color/black" />

        <ImageView
            android:id="@+id/ivNavigateToDigitFragment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:alpha="0.5"
            android:contentDescription="@string/app_label"
            app:srcCompat="@drawable/next_button_icon" />

    </RelativeLayout>

    <WLoanEditTextView
        android:id="@+id/edtEnterATMPin"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:inputType="number"
        android:maxLength="4">

        <requestFocus />
    </WLoanEditTextView>

</RelativeLayout>

Ответы [ 2 ]

0 голосов
/ 27 марта 2019

Я создаю KeyboardAnchor класс для обработки пользовательских фрагментов DialogFractive с помощью edittext`s. Итак, подумайте, что вы можете использовать подобное решение для ваших нужд.

Основная идея заключается в том, чтобы прослушивать глобальные изменения макета и изменения внутреннего макета и вычислять нижние точки во время них. А после перевести взгляды на нужные позиции.

И по умолчанию нет способа справиться с этим.

0 голосов
/ 20 марта 2019

Попробуйте использовать это вместо android:windowSoftInputMode="adjustPan".

...