简体   繁体   中英

TextView: Remove spacing and padding on top and bottom

I have one textview which size is 50 dp. I got this result like the picture below. 在此处输入图片说明
I want to remove bottom spaces in my textView ,because its height depend on the text size. And I want to receive background only into my quotation mark. Is there any way to remove the unused spaces in my textView?

<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="top"
                android:text="“"
                android:fontFamily="@font/arialbd"
                android:background="#ff0"
                android:textColor="#E8E9EF"
                android:includeFontPadding="false"
                android:textSize="50dp" />

Try this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_gravity="top|center"
    android:text="“"
    android:fontFamily="@font/arialbd"
    android:background="#ff0"
    android:textColor="#E8E9EF"
    android:includeFontPadding="false"
    android:textSize="50dp"
    android:gravity="top" />

This solution works on my case. To remove bottom padding. Set the layout_height the same size as your textSize or 1dp or 2dp less.
Set includeFontPadding="false" . Set android:lineSpacingExtra="0dp"

In your case you have to implement custom textView. check this example for reference.

U can try setting your bottom margin to a negative value.

Something like this:

android:layout_marginBottom="-10dp"

Let me know if its works, that is the simplest way but can be anothers...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM