im new to constraint layout so maybe im missing something, but Im having trouble refactoring this simple (simplified minimal example) linear layout to constraint layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/message_background"
    android:foreground="@drawable/item_selector"
    android:orientation="vertical"
    android:padding="16dp">

    <View
        android:id="@+id/view1"
        android:layout_width="match_parent"
        android:layout_height="124dp"
        android:background="#FFAABB" />

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="124dp"
        android:layout_marginTop="8dp"
        android:background="#FFEEAA" />

    <View
        android:id="@+id/view3"
        android:layout_width="match_parent"
        android:layout_height="124dp"
        android:layout_marginTop="8dp"
        android:background="#FFAAEE" />

</LinearLayout>

The key is that view2 or view3 can be gone-able, and obviously I need to still padding bottom on the parent; which is automatic in linear layout no matter the content.

So far what Ive tried is faking the parent padding with margin on items but margin_bottom on the last view doesnt work (possibly because its not constrainted bottom, but why should it be if its wrap_content height parent)

Also the background + click listener...

(And yes I know for this case I should use linear layout, no need to say that -- its a virtual example of my problems)

0 Answers