Как настроить макет с помощью ScrollView? - PullRequest
0 голосов
/ 23 сентября 2019

Я изучаю Android, и сейчас у меня проблема с ScrollView.

. Я использую ScrollView в качестве основного контейнера макета с LinearLayout в качестве дочернего элемента, потому что я быкак мои экраны поддерживают книжную и альбомную ориентацию, но это не работает так, как я хочу.

Как вы можете видеть на изображениях ниже, пространство до изображения не появляется, даже изображение обрезается, потому что нажатие клавиатурывверх макет, и он не подходит для экрана, а также в альбомной ориентации.

Может ли кто-нибудь помочь мне с настройкой макета для поддержки прокрутки без потери оригинального дизайна макета?

Код макета:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/gradient_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

        <LinearLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            tools:context=".LoginActivity"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="30dp">

            <ImageView
                android:id="@+id/sign_in_logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/trivia_wars_logo"
                android:layout_gravity="center"
                android:rotation="-8"
                android:scaleX="0.75"
                android:scaleY="0.75"
                android:padding="5dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/sign_in_input_layout_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/TextInputLayoutStyle"
                android:layout_marginTop="15dp">

                <EditText
                    android:id="@+id/sign_in_input_username"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_email_username"
                    style="@style/EditTextStyle"
                    android:inputType="textPersonName"/>

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/sign_in_input_layout_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                style="@style/PasswordInputLayoutStyle"
                android:layout_marginTop="15dp"
                app:passwordToggleEnabled="true">

                <EditText
                    android:id="@+id/sign_in_input_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_password"
                    style="@style/EditTextStyle"
                    android:inputType="textPassword"/>

            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.button.MaterialButton
                android:id="@+id/sign_in_action_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:paddingTop="12dp"
                android:paddingBottom="12dp"
                style="@style/RoundedButtonStyle"
                android:text="@string/sign_in"/>

            <com.google.android.material.button.MaterialButton
                android:id="@+id/sign_in_sign_up_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingTop="12dp"
                android:paddingBottom="12dp"
                style="@style/OutlineRoundedButtonStyle"
                android:text="@string/sign_up"/>
        </LinearLayout>
</ScrollView>

Предварительный просмотр макета:

Preview of the layout

Макет, проверенный на моем устройстве:

![Portrait layout with active keyboard

Landscape layout

Спасибо.

Ответы [ 2 ]

1 голос
/ 25 сентября 2019

Попробуйте добавить

android:windowSoftInputMode="adjustPan" 

в файл манифеста внутри вашей деятельности.

<activity
            android:name=".YourActivity"
            android:windowSoftInputMode="adjustPan">

        </activity>

вы найдете информацию о windowSoftInputMode: здесь

0 голосов
/ 25 сентября 2019

Измените LinearLayout Свойство

android:gravity="center"

вместо

android:layout_gravity="center"

Это будет работать ..

...