Вы можете использовать 2 вертикальных направляющих и ограничить ваш textView для обоих, чтобы, когда 1 направляющая переместилась, изменилась и другая, и ваш textView остался в пределах экрана.
Вот пример (не стесняйтесь перемещать рекомендации к 0,95 и 0,05):
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.MenusDesign.ExpandableCategoriesMenu.ExpandableCategoriesMenu"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:paddingBottom="5dp"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent"
tools:text="Variable text!" />
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@id/textview"
tools:layout_editor_absoluteX="0dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.0" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.18" />
Другая вещь, которую вы можете сделать, это использовать эту библиотеку , чтобы убедиться, что ваш текст изменится в соответствии с оставшимся пространством:
Если вы хотите использовать эту библиотеку добавьте это в ваш gradle:
implementation 'me.grantland:autofittextview:0.2.+'
А теперь просто создайте текстовое представление:
<me.grantland.widget.AutofitTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="2"
android:textSize="40sp"
autofit:minTextSize="16sp"
/>