In previous xml layout, I have multiple view groups with few elements inside. Hide each view group will also hide all of its child elements. Since I wanted to have flat structure and tried ConstraintLayout. Cool I know how to chain element with spread to align properly. Since flat structure does not have wrapped LinearLayout, now i have 3 views to hide instead. I would like to know if there is alternative to achieve this.
Without constraint layout
<RelativeLayout....
..........
..........
<LinearLayout
android:visibility="gone"
tools:visibility="visible"
android:id="@+id/filter_area"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblTerminal"
android:background="@color/lightGray"
style="@style/PurpleSubtitle"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
android:padding="10dp"
android:text="@string/lblTerminal"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<View
android:background="@android:color/black"
android:layout_width="1dp"
android:layout_height="match_parent"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblCategory"
android:background="@color/lightGray"
android:padding="10dp"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
style="@style/PurpleSubtitle"
android:text="@string/lblCategory"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
.......
.......
</RelativeLayout>
With constraint layout
<android.support.constraint.ConstraintLayout
.....
.....
.....
#happy that i no longer need LinearLayout for align properly
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblTerminal"
android:background="@color/lightGray"
style="@style/PurpleSubtitle"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
android:padding="10dp"
android:text="@string/lblTerminal"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintTop_toBottomOf="@+id/txt_search"
app:layout_constraintRight_toLeftOf="@+id/view3"
app:layout_constraintLeft_toLeftOf="@+id/guideline2"
app:layout_constraintHorizontal_chainStyle="spread"/>
<View
android:background="@android:color/black"
android:layout_width="1dp"
android:layout_height="50dp"
android:id="@+id/view3"
app:layout_constraintTop_toBottomOf="@+id/txt_search"
app:layout_constraintRight_toLeftOf="@+id/lblCategory"
app:layout_constraintLeft_toRightOf="@+id/lblTerminal" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/lblCategory"
android:background="@color/lightGray"
android:padding="10dp"
android:drawableRight="@drawable/i_down_yellow"
android:drawableEnd="@drawable/i_down_yellow"
style="@style/PurpleSubtitle"
android:text="@string/lblCategory"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="@+id/view3"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/view3" />
......
......
......
</android.support.constraint.ConstraintLayout>