0

I put a layout on the BottomSheetDialogFragment. In the layout, 3 widgets visible apper alternately. So one widget setVisibilty(View.VISIBLE), others setVisibility(View.GONE). But when widgets setVisibility(View.GONE), BottomSheetDialogFragment will pop to the TOP. After slided BottomSheetDialogFragment, it would move to bottom instant immediately. I don't know the reason of this situation. Someone told me that setVisibility(View.GONE) wouldn't affect lifecycle of BottomSheetDialogFragment. So the problem may be the height from layoutPrarms or behavior.

https://youtu.be/-gwA560l62k

This is the XML file. Is there the problem?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
app:layout_behavior="@string/bottom_sheet_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@drawable/bottom_sheet_background">

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/transition_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginStart="20dp"
        android:layout_marginBottom="24dp"
        app:layout_constraintBottom_toTopOf="@+id/constraintLayoutAll"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:srcCompat="@drawable/ic_dashboard_black_24dp" />

    <EditText
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="英文"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="@+id/imageView1"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintStart_toStartOf="@+id/guideline4" />

    <EditText
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="36dp"
        android:text="念書"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="@+id/imageView1"
        app:layout_constraintEnd_toStartOf="@+id/guideline4" />


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="16dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="16dp" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/primaryColor"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guideline2" />

    <Button
        android:id="@+id/test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test"
        app:layout_constraintStart_toStartOf="@+id/guideline"
        app:layout_constraintTop_toTopOf="@+id/button2" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayoutAll"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="24dp"
        android:animateLayoutChanges="true"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintEnd_toStartOf="@+id/guideline2"
        app:layout_constraintStart_toStartOf="@+id/guideline">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/constraintLayoutText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.5" />

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/TextInputLayout03"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:paddingEnd="8dp"
                app:boxStrokeColor="@color/primaryDarkColor"
                app:hintTextColor="@color/colorAccent"
                app:layout_constraintEnd_toStartOf="@+id/guideline9"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/starting_time"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:drawableRight="@drawable/schedule_24px"
                    android:focusable="false"
                    android:focusableInTouchMode="false"
                    android:hint="Starts"
                    android:imeOptions="actionNext"
                    android:paddingStart="16dp"
                    android:paddingTop="16dp"
                    android:paddingEnd="12dp"
                    android:paddingBottom="16dp" />

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

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/TextInputLayout04"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:paddingStart="8dp"
                app:boxStrokeColor="@color/primaryDarkColor"
                app:hintTextColor="@color/colorAccent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="@+id/guideline9"
                app:layout_constraintTop_toTopOf="parent">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/starting_date"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:drawableRight="@drawable/today_24px"
                    android:focusable="false"
                    android:focusableInTouchMode="false"
                    android:hint="Date"
                    android:imeOptions="actionNext"
                    android:longClickable="false"
                    android:paddingStart="16dp"
                    android:paddingTop="16dp"
                    android:paddingEnd="12dp"
                    android:paddingBottom="16dp"
                    android:text="2021/1/7" />
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/TextInputLayout05"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="8dp"
                android:paddingEnd="8dp"
                android:paddingBottom="24dp"
                app:boxStrokeColor="@color/primaryDarkColor"
                app:hintTextColor="@color/colorAccent"
                app:layout_constraintEnd_toStartOf="@+id/guideline9"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/TextInputLayout03">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/ending_time"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:drawableRight="@drawable/schedule_24px"
                    android:focusable="false"
                    android:focusableInTouchMode="false"
                    android:hint="Ends"
                    android:imeOptions="actionNext"
                    android:paddingStart="16dp"
                    android:paddingTop="16dp"
                    android:paddingEnd="12dp"
                    android:paddingBottom="16dp" />
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/TextInputLayout06"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:paddingStart="8dp"
                android:paddingBottom="24dp"
                app:boxStrokeColor="@color/primaryDarkColor"
                app:hintTextColor="@color/colorAccent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="@+id/guideline9"
                app:layout_constraintTop_toBottomOf="@+id/TextInputLayout04">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/ending_date"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="false"
                    android:drawableRight="@drawable/event_24px"
                    android:focusable="false"
                    android:focusableInTouchMode="false"
                    android:hint="Date"
                    android:imeOptions="actionNext"
                    android:paddingStart="16dp"
                    android:paddingTop="16dp"
                    android:paddingEnd="12dp"
                    android:paddingBottom="16dp"
                    android:text="2021/1/8" />

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

        </androidx.constraintlayout.widget.ConstraintLayout>

        <TimePicker
            android:id="@+id/TimePicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <DatePicker
            android:id="@+id/DatePicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

This is the Java code.

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    this.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = this.getDialog().getWindow();

    assert window != null;
    window.getDecorView().setPadding(0, 0, 0, 0);
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;

    lp.windowAnimations = R.style.BottomDialogAnimation;
    window.setAttributes(lp);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    final View view = inflater.inflate(R.layout.new_event, null);
    uiInit(view);
    setOnClickListener();
    varInit();
    return view;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(STYLE_NO_TITLE, R.style.BottomSheetDialogTheme);
}

}

PS. Sorry my English is not good. If there is any problem, please tell me. I will improve. Thanks everyone

Barr
  • 44
  • 3

1 Answers1

0

I guess problem is here lp.height = WindowManager.LayoutParams.MATCH_PARENT; this should be WRAP_CONTENT. with View.GONE view does not take any space in layout hence its moving up , you can also try View.INVISIBLE as with this view is invisible but still takes space in layout.