1

I'm experiencing some weird behaviour from my dialog when I change the padding of the ConstraintLayout Here's the 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">


        <data>

            <variable
                name="viewModel"
                type="ie.conecto.ui.salesOrder.viewModels.OrderSummaryViewModel" />
        </data>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/root_place_order_confirmation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="4dp">

            <TextView
                android:id="@+id/place_order_confirmation_dialog_header"
                style="@style/TextAppearance.MaterialComponents.Headline5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:padding="8dp"
                android:text="@{viewModel.dialogHeader}"
                android:textAlignment="center"
                android:textColor="@android:color/white"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <ScrollView
                android:id="@+id/scrollView3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:paddingTop="72dp"
                android:paddingBottom="72dp"
                app:layout_constraintBottom_toTopOf="@+id/relativeLayout"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_order_confirmation_dialog_header">
    <!--            tools:layout_editor_absoluteX="2dp">-->


                <LinearLayout
                    android:id="@+id/order_details_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="vertical"
                    android:paddingBottom="4dp">

                    <TextView
                        style="@style/TextAppearance.MaterialComponents.Caption"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/customer"
                        android:paddingStart="4dp"
                        android:paddingEnd="4dp"
                        android:text="@{viewModel.customer.code}" />

                    <TextView
                        style="@style/TextAppearance.MaterialComponents.Body1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="4dp"
                        android:hint="@string/customer"
                        android:paddingStart="4dp"
                        android:paddingEnd="4dp"
                        android:text="@{viewModel.customer.description}" />


                    <include layout="@layout/divider" />


                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/salesOrderConfirmationProductsRecyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4dp"
                        android:layout_marginBottom="4dp"
                        android:clickable="false"
                        android:focusable="false"
                        android:paddingStart="4dp"
                        android:paddingEnd="4dp"
                        app:adapter="@{viewModel.orderConfirmationProductsAdapter}"
                        app:layoutManager="LinearLayoutManager">

                    </androidx.recyclerview.widget.RecyclerView>


                    <include layout="@layout/divider" />


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4dp"
                        android:layout_marginBottom="4dp"
                        android:orientation="horizontal"
                        android:paddingStart="8dp"
                        android:paddingEnd="8dp">

                        <TextView
                            android:id="@+id/prodCountLabel"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="@string/product_count" />

                        <TextView
                            android:id="@+id/prodCount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            app:text="@{viewModel.productCount}" />

                    </LinearLayout>

                    ....
                    ....
                    ....
                    ....


                </LinearLayout>

            </ScrollView>


            <RelativeLayout
                android:id="@+id/relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:layout_marginEnd="4dp"
                android:orientation="horizontal"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent">


                <com.google.android.material.button.MaterialButton
                    android:id="@+id/buttCancelPlaceOrder"
                    style="@style/Widget.MaterialComponents.Button.TextButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toStartOf="@id/buttOk"
                    android:text="@string/butt_cancel" />


                <com.google.android.material.button.MaterialButton
                    android:id="@+id/buttOk"
                    style="@style/Widget.MaterialComponents.Button.TextButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:text="@string/butt_ok" />
            </RelativeLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </layout>

this gives me the following dialog:

Expected Outcome

However if I change the padding on the Constraint layout to 2dp:

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/root_place_order_confirmation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="2dp">

I get this dialog:

Incorrect appearance dialog

I'd prefer if the padding was 2dp but anything lower than 4dp collapses the dialog. Any idea why this is happening?

ShanieMoonlight
  • 1,623
  • 3
  • 17
  • 28
  • It's not the same problem but I have asked [a question](https://stackoverflow.com/questions/55760811/why-my-dialog-layout-wont-spread-correctly) where the dialog didn't spread accordingly. and the solution was to set the layout attributes programmatically. Maybe it will work for you , you can also check [Add padding on view programmatically](https://stackoverflow.com/questions/9685658/add-padding-on-view-programmatically) – Tamir Abutbul Apr 10 '20 at 16:30
  • Thanks for the suggestion @TamirAbutbul. I tried it but it didn't work. Maybe I have to live with 4dps. – ShanieMoonlight Apr 12 '20 at 10:48
  • Another solution I can suggest is to try and use [sdp](https://github.com/intuit/sdp) library – Tamir Abutbul Apr 12 '20 at 10:51

0 Answers0