I am trying to align a TextView to be centered in a relative layout but also to the right of an ImageView. I would like it to look like this.
[-(image)-----some text here------------]
I'm able to do this with the code below, but if the text becomes too long it overlaps the image.
<?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="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/small_padding"
android:paddingBottom="@dimen/small_padding"
android:background="@color/White">
<ImageView
android:id="@+id/navMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home_icon"
android:layout_marginEnd="@dimen/small_padding"
android:contentDescription="@string/abc_search_hint"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/actionBarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/profile"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/Black"
android:maxLines="1"
android:ellipsize="end"
android:contentDescription="@string/title_activity_connect"
android:layout_centerInParent="true" />
</RelativeLayout>
I have tried aligning the TextView to the right of the ImageView but it stops centering in parent if I do that. Any help is appreciated
You could try something like this. I used a radio group instead of a linear layout for this but it should still work. Have a the linear layout horizontal as you already do and then make the layout gravity center then just put the image first then the text view
EDIT: I don't know if the margin attributes for the buttons I have work on text views but padding left on the text might work