Прежде чем ответить, пожалуйста, учтите, что я попробовал все следующие решения:
- Как настроить раскладку при появлении программной клавиатуры
- Переместить раскладки вверх при использовании программной клавиатуры
- Программная клавиатура изменяет размер фонового изображения на Android
- https://www.semicolonworld.com/question/47224/how-to-adjust-layout-when-soft-keyboard-appears
На экране входа в систему я хочу переместить мое фоновое изображение вверх вместе с другими элементами. Вот xml:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.auth.RegisterFragment"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View"/>
<variable
name="vm"
type="com.clash.android.ui.auth.AuthViewModel"/>
</data>
<RelativeLayout
android:background="@drawable/bg_login_clashpic"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/footerLayout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/errorText"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="48dp"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textSize="16sp"
android:textColor="@color/error"
tools:text="@string/error_sign_in"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:background="@color/transparent"
app:tabIndicatorColor="@color/colorAccent"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/dark_grey"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.tabs.TabItem
android:text="@string/sign_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.google.android.material.tabs.TabItem
android:text="@string/log_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</com.google.android.material.tabs.TabLayout>
<ViewSwitcher
android:id="@+id/vsFields"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/layRegister"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/userNameEdit"
android:text="@={vm.userName}"
android:maxLength="@integer/username_max_length"
android:inputType="textPersonName"
android:hint="@string/username"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:layout_width="match_parent"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<EditText
android:id="@+id/emailEdit"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:maxLength="@integer/fullname_max_length"
android:text="@={vm.email}"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<EditText
android:id="@+id/passwordEdit"
android:maxLength="256"
android:inputType="textPassword"
android:text="@={vm.password}"
android:hint="@string/password"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<EditText
android:id="@+id/confirmEdit"
android:maxLength="256"
android:inputType="textPassword"
android:text="@={vm.confirm}"
android:hint="@string/confirm"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/signUpButton"
android:textSize="16sp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:onClick="@{ v -> vm.onRegisterClick()}"
android:gravity="center"
android:textColor="@color/grey"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:text="@string/sign_up"
android:layout_height="48dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layLogin"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editEmail"
android:inputType="textEmailAddress"
android:maxLength="@integer/fullname_max_length"
android:text="@={vm.email}"
android:hint="@string/email"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<EditText
android:id="@+id/editPassword"
android:inputType="textPassword"
android:text="@={vm.password}"
android:hint="@string/password"
android:textColorHint="@color/dark_grey"
android:textColor="@color/grey"
android:backgroundTint="@color/dark_grey"
android:textCursorDrawable="@null"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_height="48dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/buttonSignIn"
android:gravity="center"
android:textSize="16sp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@color/grey"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:text="@string/log_in"
android:layout_height="48dp"/>
</RelativeLayout>
</LinearLayout>
</ViewSwitcher>
</LinearLayout>
</RelativeLayout>
</layout>
![Clean state](https://i.stack.imgur.com/dFBOc.png)
1. Желаемый эффект на самом деле больше похож на то, когда я использую android:windowSoftInputMode="adjustPan"
в деятельности моего манифеста. При adjustPan
root RelativeLayout
с изображением, установленным в качестве фона, приятно подталкивается вверх, как я хочу, но все, что находится ниже сфокусированного элемента, обрезается, чего я не хочу.
При использовании android:windowSoftInputMode="adjustResize"
:
2. - с указанным выше xml, установив изображение непосредственно в android:background="@drawable/loginpic"
, изображение будет сдавлено.
![enter image description here](https://i.stack.imgur.com/0cyWg.png)
3. - при добавлении ImageView
изображение перемещается вверх, но не так сильно, как нижние элементы Это означает, что указанные элементы будут выше на картинке
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/clashloginpic"
android:gravity="bottom" >
</bitmap >
![enter image description here](https://i.stack.imgur.com/jQGfD.png)
4. - при использовании ScrollView
, чтобы обернуть все, добавление изображения в ImageView
приведет к странному поведению, когда мы сможем прокрутить, и мы увидим огромную белую часть между экранной клавиатурой и самым нижним элементом (кнопка входа в систему)
![enter image description here](https://i.stack.imgur.com/8ocOq.png)
5. - лучший результат с ScrollView
- при установке растрового элемента в качестве фона (android:gravity="bottom"
ключ). Когда отображается программная клавиатура, фоновое изображение прокручивается вместе с нижними элементами на той же высоте. НО с растровым изображением, изображение увеличено до предела и больше не распознается. Экран НЕ прокручивается (по желанию).
![with soft keyboard](https://i.stack.imgur.com/TO9kn.png)
В конце я хочу знать, как Избегайте обрезки элементов ниже сфокусированного при использовании 1. (с adjustPan
) ИЛИ как отцентрировать мою картинку в растровом изображении xml с помощью 5. И то и другое даст мне желаемое эффект.