How to align the text to top of TextView?

后端 未结 6 763
梦如初夏
梦如初夏 2020-12-04 16:58

How to align the text to top of a TextView?
Equivalent Android API for Swings setInsets()?
that is top of text should start be in (0,0) of TextView



        
6条回答
  •  清歌不尽
    2020-12-04 17:19

    The actual font itself has extra whitespace on the top and bottom I believe.

    Usually what I do is give the view negative margins. The issue is that this looks bad when devices come with different fonts.

    android:layout_marginTop="-5dp"
    android:layout_marginBottom="-5dp"
    

    You will have to adjust based on the text size, bigger text sizes require more negative padding.

提交回复
热议问题