Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

android - Views inside Bottom sheet behavior changes its alignment after the keyboard appears and disappears

I have been creating a simple android application for a personal project. I have included a BottomSheetBehavior in my layout. When the keyboard appears and disappears , the alignment of the views inside the BottomSheetBehavior changes its alignment and moves down below the screen.

Actual Layout before the appearance of keyboard --> Original Screen

Appearance of keyboard in the layout

Layout after the appearance of keyboard --> This is where the actual problem of mine. Look at the alignment of the text inside the BottomSheetBehavior

Layout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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/colorPrimaryDark"
    android:fitsSystemWindows="true"
    tools:context=".activities.CreateNoteActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/topbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true">

        <ImageView
            android:id="@+id/imageBack"
            android:layout_width="@dimen/_22sdp"
            android:layout_height="@dimen/_22sdp"
            android:layout_marginStart="@dimen/_6sdp"
            android:layout_marginTop="@dimen/_17sdp"
            android:layout_marginEnd="@dimen/_12sdp"
            android:contentDescription="@string/app_name"
            android:src="@drawable/ic_back"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:tint="@color/colorIcons" />

        <ImageView
            android:id="@+id/imageSave"
            android:layout_width="@dimen/_20sdp"
            android:layout_height="@dimen/_20sdp"
            android:layout_marginEnd="@dimen/_12sdp"
            android:background="@drawable/background_done_button"
            android:contentDescription="@string/app_name"
            android:padding="@dimen/_4sdp"
            android:src="@drawable/ic_done"
            app:layout_constraintBottom_toBottomOf="@id/imageBack"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/imageBack"
            app:tint="@color/colorIcons" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/_40sdp"
        android:layout_marginTop="@dimen/_60sdp"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/_10sdp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true">

            <EditText
                android:id="@+id/inputNotetitle"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_35sdp"
                android:layout_marginStart="@dimen/_12sdp"
                android:layout_marginTop="@dimen/_15sdp"
                android:layout_marginEnd="@dimen/_12sdp"
                android:background="@null"
                android:fontFamily="@font/ubuntu_bold"
                android:hint="Title"
                android:imeOptions="actionDone"
                android:importantForAutofill="no"
                android:includeFontPadding="false"
                android:inputType="text"
                android:textColor="@color/white"
                android:textColorHint="@color/white"
                android:textSize="@dimen/_23ssp"
                app:layout_constraintTop_toBottomOf="@id/topbar"
                tools:ignore="NotSibling" />

            <TextView
                android:id="@+id/textDateTime"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:fontFamily="@font/ubuntu_regular"
                android:includeFontPadding="false"
                android:textColor="@color/colorIcons"
                android:textSize="@dimen/_10ssp"
                app:layout_constraintEnd_toEndOf="@id/inputNotetitle"
                app:layout_constraintStart_toStartOf="@id/inputNotetitle"
                app:layout_constraintTop_toBottomOf="@id/inputNotetitle"/>

            <EditText
                android:id="@+id/inputNoteSubTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_12sdp"
                android:layout_marginTop="@dimen/_15sdp"
                android:layout_marginEnd="@dimen/_12sdp"
                android:background="@null"
                android:fontFamily="@font/ubuntu_medium"
                android:hint="Note Subtitle"
                android:importantForAutofill="no"
                android:includeFontPadding="false"
                android:inputType="textMultiLine"
                android:paddingTop="@dimen/_8sdp"
                android:paddingBottom="@dimen/_8sdp"
                android:textColor="@color/colorTextSubtitle"
                android:textColorHint="@color/colorTextHint"
                android:textSize="@dimen/_15ssp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/viewSubtitleIndicator"
                app:layout_constraintTop_toBottomOf="@id/textDateTime"/>

            <View
                android:id="@+id/viewSubtitleIndicator"
                android:layout_width="@dimen/_5sdp"
                android:layout_height="0dp"
                android:layout_marginStart="@dimen/_12sdp"
                android:background="@drawable/background_subtitle_indicator"
                app:layout_constraintBottom_toBottomOf="@id/inputNoteSubTitle"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@id/inputNoteSubTitle"/>

            <LinearLayout
                android:id="@+id/layoutImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_12sdp"
                android:layout_marginTop="@dimen/_15sdp"
                android:layout_marginEnd="@dimen/_12sdp"
                android:paddingTop="5dp"
                android:paddingBottom="5dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:background="@drawable/linear_border_image"
                app:layout_constraintTop_toBottomOf="@id/inputNoteSubTitle"
                android:visibility="gone">

                <ImageView
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_20sdp"
                    android:src="@drawable/ic_image"
                    app:tint="@color/white" />

                <TextView
                    android:id="@+id/imageClicktoView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/click_to_view"
                    android:layout_weight="1"
                    android:fontFamily="@font/ubuntu_bold"
                    android:textSize="@dimen/_12ssp"
                    android:textAlignment="center"
                    android:textColor="@color/white" />

                <ImageView
                    android:id="@+id/imageRemoveImage"
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_20sdp"
                    android:contentDescription="@string/app_name"
                    android:src="@drawable/ic_delete"
                    app:tint="@color/colorDelete" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/layoutWebURL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/_12sdp"
                android:layout_marginTop="@dimen/_15sdp"
                android:layout_marginEnd="@dimen/_12sdp"
                android:paddingTop="5dp"
                android:paddingBottom="5dp"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:visibility="gone"
                android:background="@drawable/linear_border_weburl"
                app:layout_constraintTop_toBottomOf="@id/layoutImage"
                tools:ignore="UseCompoundDrawables">

                <ImageView
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_20sdp"
                    android:src="@drawable/ic_weblink"
                    app:tint="@color/white" />

                <TextView
                    android:id="@+id/textWebURL"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:autoLink="web"
                    android:textAlignment="center"
                    android:fontFamily="@font/ubuntu_regular"
                    android:includeFontPadding="false"
                    android:textSize="@dimen/_13ssp" />

                <ImageView
                    android:id="@+id/imageRemoveWebURL&quo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...