I want to avoid nested layout, to improve my app performance.
Hence, I tried the following
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="30dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/title_text_view"
android:background="#ffd600"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Title\nTitle"
app:layout_constraintEnd_toStartOf="@+id/pin_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/pin_text_view"
android:background="#ff0000"
android:textColor="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Pin" />
<TextView
android:id="@+id/body_text_view"
android:background="#304ffe"
android:textColor="#ffffff"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title_text_view"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Body" />
</android.support.constraint.ConstraintLayout>
The output is as follow.
During runtime, I might change the visibility of title_text_view
(yellow) to View.GONE
.
But, it will looks like the follow. I don't wish pin_text_view
(red) to be covered up by body_text_view
(blue)
What I wish to have is
One of the way to overcome, is after changing the visibility of title_text_view
(yellow) to View.GONE
, I need use Java code to manual update app:layout_constraintTop_toBottomOf
of body_text_view
(blue) - Android : How to programatically set layout_constraintRight_toRightOf "parent"
From
<TextView
android:id="@+id/body_text_view"
...
app:layout_constraintTop_toBottomOf="@+id/title_text_view"
to
<TextView
android:id="@+id/body_text_view"
...
app:layout_constraintTop_toBottomOf="@+id/pin_text_view"
But, this will make my code more difficult to be maintained.
Is there any easier way, without involving Java code, and without nested layout?