Reputation: 6459
I have a custom component, that has an ImageView
, and a Text. My problem is, if I set the text centerHorizontal=true
in the layout, the text centers ok, but if the text is too long it overlaps on the image view. If I set layout_toRightOf="@+id/imageviewid"
, the text is not overlapped, but the text looks too close to the image view. I would like my text be centered, but without overlapping the ImageView.
I checked this, that is the solution I tried, but it does not fit to me.
The Layout:
<?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">
<ImageView
android:layout_width="40dp"
android:layout_height="30dp"
android:id="@+id/imagecolor"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textcolor"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:textColor="@color/white"
android:layout_centerHorizontal="true"
android:text="Placeholder"
android:layout_toRightOf="@+id/imagecolor"/>
<Space
android:layout_width="20dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Upvotes: 0
Views: 746
Reputation: 109
You can give the margin from the left to your text view , it would always make distance with left image view.
android:layout_marginLeft="10dp" .... .....
Upvotes: 2