【问题标题】:How make layout scrollable when softKeyBoard hides buttons and other elements [ANDROID]当softKeyBoard隐藏按钮和其他元素时如何使布局可滚动[ANDROID]
【发布时间】:2022-01-09 23:43:42
【问题描述】:

我的目标是制作带有页脚文本的登录用户界面,而且页面应该是可滚动的,只要内容不会显示在视图上。

我在布局中添加了滚动视图,但是当键盘出现时,滚动不起作用任何建议?那些不起作用,我不希望那个按钮出现在键盘上方

android:windowSoftInputMode="stateHidden|adjustPan" android:windowSoftInputMode="stateHidden|adjustResize"

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".auth.AuthFragment">
    
            <androidx.core.widget.NestedScrollView
                android:id="@+id/scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintBottom_toTopOf="@id/footer">
    
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/authConstraint"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
    
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/usernameInputLayout"
                        android:layout_width="384dp"
                        android:layout_height="75dp">
    
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/usernameInputEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
    
                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/uSubmit"
                        android:layout_width="match_parent"
                       app:layout_constraintTop_toBottomOf="@+id/usernameInputLayout" />
    
                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/uRegistration"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:backgroundTint="#2C2C2E"
                        android:text="SIGNIN"
                        android:textSize="30sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="@+id/uSubmit"
                        app:layout_constraintStart_toStartOf="@+id/uSubmit"
                        app:layout_constraintTop_toBottomOf="@+id/uSubmit" />
                </androidx.constraintlayout.widget.ConstraintLayout>
            </androidx.core.widget.NestedScrollView>
    
            <FrameLayout
                android:id="@+id/footer"
                android:layout_width="match_parent"
                android:layout_height="70dp"
                android:background="@color/black"
                app:layout_constraintBottom_toBottomOf="@+id/scroll"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent">
    
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <TextView
                        android:layout_width="358dp"
                        android:layout_height="wrap_content"
                </androidx.constraintlayout.widget.ConstraintLayout>
            </FrameLayout>
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    </layout>

【问题讨论】:

    标签: java android kotlin scroll keyboard


    【解决方案1】:
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:fillViewport="true">
    
               <androidx.constraintlayout.widget.ConstraintLayout
                   android:layout_width="match_parent"
                   android:layout_height="match_parent">
    
                  <View
                     android:id="@id/view_1"
                     ...
                     app:layout_constraintTop_toTopOf="parent" />
    
                  <View
                     android:id="@id/view_2"
                     ...
                     app:layout_constraintTop_toBottomOf="@id/view_1" />
    
                  <View
                     android:id="@id/view_3"
                     ...
                     app:layout_constraintTop_toBottomOf="@id/view_2" />
    
                  <View
                     android:id="@id/view_4"
                     ...
                     app:layout_constraintTop_toBottomOf="@id/view_3"
                     app:layout_constraintBottom_toBottomOf="parent" />
    
               </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.core.widget.NestedScrollView>
    </LinearLayout>
    

    确保在所有视图(父顶部和父底部)之间都有约束。 从我的示例中,您可以看到约束 PARENT_TOP PARENT_BOTTOM

    【讨论】:

    • 感谢 Dmytro,感谢您的回复,但它不起作用。当键盘打开时,它会向下滚动一点,我检查了小分辨率设备,当视图超出显示滚动时,它会按预期工作。问题是键盘打开时:(并且它隐藏了一些视图
    • 尽量不要在 android manifest 中使用任何带有活动的标志
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多