Center TextView horizontally in RelativeLayout



I'm trying to center a TextView vertically in a RelativeLayout. The preview of Android Studio displays the layout how I want it:


Preview of Android Studio


But my phone shows this (I use a custom font):


What I get on Android


Why is the TextView not centered on my device?


The XML:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="110dp"
android:padding="10dp"
android:background="@drawable/favourites_item_bg" >

<RelativeLayout
android:id="@+id/color"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="#63FF87" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/color"
android:layout_toEndOf="@+id/color"
android:padding="10dp">

<TextView
android:id="@+id/num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1."
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:id="@+id/hex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#63FF87"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

</RelativeLayout>

</RelativeLayout>

No comments:

Post a Comment