I have the following layout. In the example below, you will notice that Y
was not able to be laid out to its full width, and it was cut-off (truncated) due to the lack of vertical space.
I would like to be able to programmatically identify when this happens (as a Boolean
. How can I achieve this?
Note: the answer to this question will enable a workaround for this problem How can I use ConstraintLayout to have the first View shrink to fit remaining space?
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fbe9e7"
android:gravity="center"
android:text="X"
android:textSize="96sp">
</TextView>
</ScrollView>
<TextView
android:id="@+id/text_Y"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f3e5f5"
android:gravity="center"
android:text="Y"
android:textSize="96sp"
app:layout_constraintTop_toBottomOf="@+id/scrollView"
app:layout_constraintBottom_topTopOf="@+barrier_bottom"/>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="text_Z,spacer" />
<TextView
android:id="@+id/spacer
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_constraintTop_topBottomOf="@+id/text_Y"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView
android:id="@+id/text_Z"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e1f5fe"
android:gravity="center"
android:text="Z"
android:textSize="96sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="1" />
</androidx.constraintlayout.widget.ConstraintLayout>