1

I'm trying to understand the UI behavior when parent layout_width/layout_height is set to wrap_content while in son layout_width/layout_height is set to match_parent. I found a old question in stackoverflow combining wrap_content on parent and fill_parent on child

But the post writer tried to achieve that all his sons (buttons in his case) will be at the same height, the response refereed to this purpose and not to how this conflict is set. For example in the following code i have written:

     <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">


    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="25dp"
        android:layout_margin="@dimen/cardview_compat_inset_shadow">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />


        </LinearLayout>

    </androidx.cardview.widget.CardView>

</RelativeLayout>

I ran this code and CardView width take occupied all the screen (it seems that layout_width (match_parent) in CardView overcome on layout_width (wrap_content) in RelativeLayout. While CardView height occupied only both TextViews and not all the screen ( it seems that layout_width (wrap_content) in RelativeLayout overcome on layout_width (match_parent) in CardView

I can't find any "rule" how the conflict should be set. I hope someone can help me understanding the logic or facts on how this conflict is set?

Eitanos30
  • 1,331
  • 11
  • 19

0 Answers0