在開發Android的時候,因為不同的手機螢幕大小會造成跑版,所以會隨著螢幕動態調整大小的功能很重要。

我的OS是 Windwos 10, Android 是以下版本:

1.jpg

以下紀錄一下Android內元件字體如何自動依據螢幕大小進行調整。

android:autoSizeTextType="uniform"

 

舉例來說,寫在 TextView中,黃底部份。

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="上方文字"
    android:autoSizeTextType="uniform"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

這樣字體就會隨著元件大小有所改變。

打完收工

arrow
arrow

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()