如何讓Android 文字(TextView)消除上下邊距

Android的Textview預設會依字體大小而在文字留了上邊距與下邊距,如此一來可以讓不同的TextView之間具有預設的間距,讓視覺上不會太過擁擠的感覺。 但如果有排版對齊的需求時就會產生困擾,例如像是在多個TextView使用了不同的字體大小但要又在TextView之間都留下相同間距的時候。

解決的方法,在Layout XML的TextView加上includeFontPadding、marginTop與marginBottom即可

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginBottom="-5dp"
   android:layout_marginTop="-5dp"
   android:includeFontPadding="false"/>

Reference:
http://stackoverflow.com/questions/4768738/android-textview-remove-spacing-and-padding-on-top-and-bottom

留言

這個網誌中的熱門文章

ISO 27001 LA 主導稽核員 考照心得

Android如何實作強制App版本更新

如何實作從API抓取資料顯示在列表頁(ListView)上