Lampione
Lampione

Reputation: 1608

TextView digit taking too much space

I know that this has already been asked a tons of times but I have a different question.

When I set a single digit in a textview and I set the textSize to be a certain big value (in my case 15pt) this is what pretty much happen:

TextView unused space

As you can see, the editor show a lot of unused space on top and bottom of the number. I know that this is somewhat font-related.

Is there any way to fix this?

Just for clarification, I'm adding a code so you can test yourself:

<TextView
            android:id="@+id/text_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:textSize="15pt"
            android:textColor="@color/accent_material_dark"
            android:gravity="center"/>

Further clarification, the red rectangles show the space I'd like to remove:

TextView unused space - clarification

Thank you in advance.

EDIT:

<RelativeLayout
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:gravity="center">

    <Button
        android:id="@+id/dial_number_two"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_centerInParent="true"
        android:background="@drawable/ripple_number"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:orientation="vertical"
        android:gravity="center"
        android:clickable="false"
        android:focusable="false"
        android:elevation="10dp">

        <TextView
            android:id="@+id/text_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:textSize="15pt"
            android:textColor="@color/accent_material_dark"
            android:background="#ff0000"
            android:gravity="center"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABC"
            android:textSize="4pt"
            android:visibility="gone"
            android:textColor="@color/background_material_light"
            android:gravity="center"/>

    </LinearLayout>

</RelativeLayout>

Upvotes: 2

Views: 1473

Answers (2)

azurh
azurh

Reputation: 440

I also had this issue and almost solved it by setting the textview's height equal to it's textsize.

So, in your case, set the TextView height to 15pt, or 15sp if you use sps for text size.

Upvotes: -1

Simas
Simas

Reputation: 44128

Looks like you want:

android:includeFontPadding="false"

which excludes top and bottom padding for font accents.

Upvotes: 8

Related Questions