Android 字型大小怎麼自適應不同解析度?

來源:互聯網
上載者:User

不同解析度下,字型大小怎麼適應?

假設需要適應320x240,480x320解析度。在res目錄下建立檔案夾values-320x240, values-480x320。然後在檔案夾 values ,values-320x240 和  values-480x320 下建立xml檔案dimens.xml,該xml檔案內容如下:


[plain] <?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <dimen name="btnTextSize">14dip</dimen> 
</resources> 
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <dimen name="btnTextSize">14dip</dimen>
</resources>
針對不同的解析度,btnTextSize的值不同。在布局檔案中,用下面的方式引用該值:


[html]<TextView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:gravity="center" 
    android:id="@+id/lblSet" style="@style/btntext" android:textSize="@dimen/btnTextSize"> 
</TextView> 
<TextView android:layout_width="fill_parent"
 android:layout_height="wrap_content" android:gravity="center"
 android:id="@+id/lblSet" style="@style/btntext" android:textSize="@dimen/btnTextSize">
</TextView>
通過這種方法,可以方便設定在不同解析度下,字型的大小了。當然,不僅僅字型大小,寬和高等其他的一些屬性,也可以通過類似的方式來設定!


摘自 心靈淨土

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.