Попробуйте мое решение:
<?xml version="1.0" encoding="utf-8"?>
<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="48dp"
android:background="#FF0000">
<LinearLayout
android:id="@+id/container_start"
android:layout_width="48dp"
android:layout_height="0dp"
android:background="#00FF00"
android:orientation="horizontal"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/text_title" />
<TextView
android:id="@+id/text_title"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
app:layout_constraintStart_toEndOf="@id/container_start"
app:layout_constraintEnd_toStartOf="@id/container_end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:maxLines="1"
android:ellipsize="end"
android:text="Title Title Title Title" />
<LinearLayout
android:id="@+id/container_end"
android:layout_width="96dp"
android:layout_height="0dp"
android:background="#0000FF"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/text_title"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Я изменяю ширину и высоту на 0dp, потому что, если мы ограничиваем стороны, мы можем использовать его для растягивания вида.
Затем я добавляю android:gravity="center"
в ваш TextView. И еще добавляю app:layout_constraintHorizontal_chainStyle="spread_inside"
Если есть вопросы, давайте обсудим в комментариях
Обновление 1
Если вы хотите реализовать панель инструментов в вашем приложении я предлагаю вам использовать androidx.appcompat.widget.Toolbar
:
<?xml version="1.0" encoding="utf-8"?>
<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="?attr/actionBarSize"
android:background="#FF0000">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:navigationIcon="@drawable/ic_arrow_back"
app:menu="@menu/toolbar_actions">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Toolbar Title TitleTitleTitleTitleTitle"
android:textColor="@android:color/black"
android:textSize="18sp"
android:ellipsize="end"
android:textStyle="bold"
android:layout_gravity="center" />
</androidx.appcompat.widget.Toolbar>
</androidx.constraintlayout.widget.ConstraintLayout>
И меню XML разметка
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="action_one"
android:icon="@drawable/ic_android"
android:title="action 1"
app:showAsAction="ifRoom"/>
<item android:id="action_two"
android:icon="@drawable/ic_android"
android:title="action 2"
app:showAsAction="ifRoom"/>
</menu>
Результат:
Обновление 2
Попробуйте это, может быть, это то, что вам нужно.
<?xml version="1.0" encoding="utf-8"?>
<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="48dp"
android:background="#FF0000">
<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:text="Title Title Title Titlsase"
android:textColor="@android:color/black"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/center_line"
app:layout_constraintEnd_toEndOf="@id/center_line"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/center_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.5"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/container_start"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#00FF00"
android:orientation="horizontal"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/text_title" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back"
android:layout_marginStart="10dp"
android:layout_gravity="start|center_vertical" />
</LinearLayout>
<LinearLayout
android:id="@+id/container_end"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#0000FF"
android:orientation="horizontal"
android:gravity="end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/text_title">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_android"
android:layout_marginEnd="10dp"
android:layout_gravity="end|center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_android"
android:layout_marginEnd="10dp"
android:layout_gravity="end|center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_android"
android:layout_marginEnd="10dp"
android:layout_gravity="end|center_vertical" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Результат: