TextView without any default padding [duplicate]

2019-06-26 12:29发布

Possible Duplicate:
I want textView without any default padding while increasing size of textView

I want to remove default padding on TextView. When i increase the size of TextView then its padding size increases automatically. even i set background of text View as "@null". i just want to show only text without any padding. my View looks like this first images and i want to show like second images.

This First link shows View is displaying.

http://www.imageurlhost.com/images/487vskfx1aj01f9e9g40.png

This second link show Layout view that i want to show without giving any -margin

http://www.imageurlhost.com/images/ijuyxpcub1oqy1w66h.png

2条回答
混吃等死
2楼-- · 2019-06-26 13:21

It's called font padding. You can disable it with mTextView.setIncludeFontPadding(false); or xml attribute android:includeFontPadding="false"

查看更多
等我变得足够好
3楼-- · 2019-06-26 13:28

You can remove the padding from xml by setting the padding to 0dp

Try something like this:

<TextView
    android:padding="0dp"
 ...
 </TextView>

Note that if you do that, you can't use gravity anymore, since that is working using padding.

If you want to remove only top and bottom padding, you can set paddingBottom and paddingTop to 0dp and work with the side padding.

Cheers, Arkde

查看更多
登录 后发表回答