How to make Android fonts self-adapting to screen resolution

Source: Internet
Author: User

How does the Android font size adapt to the change in resolution at different resolutions?

Suppose you need to adapt to 320x240,480x320 resolution. Create a new folder under the Res directory values-320x240, values-480x320. Then in the folder values, values-320x240 and values-480x320 new XML file Dimens.xml, the XML file content is as follows:


<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<dimen name= "Btntextsize" >14dip</dimen>
</resources>
For different resolutions, the value of the btntextsize is different. In the layout file, reference the value in the following way:


<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>

This way, you can easily set the size of the font at different resolutions. Of course, not only the font size, width and other properties of the other, but also can be set in a similar way




Layout to set the image adaptive size, and set the maximum width height, when the width of the picture is greater than the maximum value set, the width of the high value is the maximum value set.



<imageview android:id= "@+id/image_view"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:adjustviewbounds= "true"
Android:maxwidth= "42DP"
android:maxheight= "42DP"
Android:scaletype= "Fitcenter"
android:layout_marginleft= "3DP"
android:src= "@drawable/icon"
/>

How to make Android fonts self-adapting to screen resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.