Android Font Size Adaptive

Source: Internet
Author: User

To adapt to which resolution you add values-xxxxxxx (such as: values-values-1024x600) folder under your project res, the new Dimens.xml file format in the folder is as follows:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <dimen name= "Text_size" >40sp</dimen> <           /resources> layout File Reference: <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "ABCDEFG" android:textsize= "@dimen/text_size"/> A brief description of font units:

px(Pixel):Screen actual pixel, often said resolution1024*768pixels, is horizontal1024PX,Longitudinal768px, different devices show the same effect.
inch(Inches):Physical dimensions of the screen,per inch equals2.54Cm.
mm(Mm):The physical size of the screen.
PT(Point)  :The physical size of the screen.1/72Inches.
Dp/dip:160 dot on the monitor, 1DP = 1pxdp and px&NBSP;
sp    : best fortextsize Java: Float dimen =resources.getdimen (r.dimen.some_name)  
Xml example:

· <?xmlversion= "1.0" encoding= "Utf-8"?>

· <resources>

· <dimenname= "One_pixel" >1px</dimen>

· <dimenname= "double_density" >2dp</dimen>

· <dimenname= "sixteen_sp" >16sp</dimen>

· </resources>


Calculate a certain percentage of font size by screen size:

    1. Public static int getfontsize (int screenwidth, int screenheight) {
    2. screenwidth=screenwidth>screenheight?screenwidth:screenheight;
    3.         int rate =  (int) ( 5* (float)  screenwidth/< Span style= "color: #c00000;" >320)
    4. return rate<?    14:rate;
    5. }

Android Font Size Adaptive

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.