简体   繁体   中英

background drawable does not fit in bound of TextView in Android

I made a TextView which has attributes of background, gravity and so on. and i made a drawable resource file for the TextView's background. and this is the xml. 在此处输入图像描述

and i added the drawable resource into background of the TextView. 在此处输入图像描述

but the problem is, the background doesn't fit in Textview's bound. please look at this photo.

在此处输入图像描述

there is a gap very slightly. the background color area is upper than TextView's area. so i tried to use includeFontPadding attribute but it didn't work. how can i fix it?

I would advise you to check this on real device/emulator, not on preview in AS. use Show Layout Bounds option from developer options for verification, make some full-resolution screen shot and check on it. it will be properly placed

content of any View , including its background, is always places inside its bounds. really, always, its just impossible to get outside with a single pixel (due to layout building and drawing mechanism)

Nothing is wrong with the code. In the Design Editor, it shows like this when we use any background drawable with any view. There is not any kind of a glitch.

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