I have code below which center aligns TextView but its a hack. Please see my comment in between.
Is there a way I can achieve the same result but without the hack?
Please note I want TextView to be center aligned wrt. Screen irrespective of the width of the sibling (in case below 'action_back')
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/action_back"
layout="@layout/action_back"
android:layout_height="match_parent"
android:layout_width="wrap_content" />
<!--
TODO:
hack TextView width is set as match_parent to
make it center align with Screen dimensions,
which overlaps with back btn. I could
not find another way to center it.
-->
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="17sp"
android:textStyle="bold" />
</RelativeLayout>
