Center text in the TextView of a RecyclerView row



I have a RecyclerView in my app. Below's an xml code of its row:



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://ift.tt/nIICcg"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp">

<TextView
android:paddingLeft="-1.5dp"
android:paddingTop="-1.5dp"
android:textColor="#fff"
android:id="@+id/text_with_icon"
android:layout_gravity="center_vertical"
android:layout_width="40dp"
android:layout_height="40dp"
android:text="A"
android:textAlignment="center"
android:textSize="22sp"
android:gravity="center"
android:background="@drawable/circle"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:textColor="#000"
android:gravity="center_vertical"
android:textSize="16sp"
android:textStyle="bold"
android:layout_gravity="left|top"
android:id="@+id/list_title"
android:layout_marginLeft="72dp"
android:padding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dummy text"
android:layout_marginStart="72dp"
android:layout_toRightOf="@+id/text_with_icon" />

<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_marginLeft="77dp"
android:textStyle="normal"
android:textColor="#000"
android:textSize="12sp"
android:gravity="center_vertical"
android:text="Lorem ipsum dolor sit amet, consectetur..."
android:layout_alignLeft="@+id/list_title"
android:layout_alignStart="@+id/list_title"
android:layout_alignParentBottom="true"
android:layout_gravity="left|bottom"
android:layout_marginBottom="8dp"/>
</FrameLayout>


The Android Studio preview shows that it looks like on the following screenshot: custom row template


So, it looks like the letter in the red circle is well centered and here comes the first problem. In the screenshot from an emulator it is easy to notice that all the letters in those circles are not in the center. How can I center them? Emulator screenshot


And now the second issue. In the emulator screenshot if you look at the third item of the list ("Something3"), it has no description text below the text in bold. Is is possible to vertically center it in the row if there's no description? Circles in the list are backgrounds of the textview and are shapes in separate xml file (circle.xml):



<shape
xmlns:android="http://ift.tt/nIICcg"
android:shape="oval">
<solid android:color="@color/primary"/>
</shape>

No comments:

Post a Comment