How to make the android font adaptive screen resolution

Source: Internet
Author: User
In different resolutions, how does the font size of Android adapt to resolution changes?

Assume that the resolution is 320x240,480 x320. Create a folder values-320x240, values-480x320 under the res directory. Then create the XML file dimens. xml under the folder values, values-320x240, and values-480x320. The content of the XML file is as follows:

1234 XML version = "1.0" encoding = "UTF-8" ?> resources > dimen name = " btntextsize " 14dip dimen resources >

For different resolutions, Btntextsize values are different. Reference the value in the layout file as follows:

1234 < 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 method makes it easy to set the font size at different resolutions. Of course, you can set the font size, width, and other attributes in a similar way.

 

 

 

Set the adaptive size of the image in layout and set the maximum width and height. When the image width is greater than the maximum value, the high value of the width is the maximum value.

 

[XHTML] View plaincopyprint?
  1. <Imageview Android: ID="@ + ID/image_view"
  2. Android: layout_width="Wrap_content"
  3. Android: layout_height="Wrap_content"
  4. Android: adjustviewbounds="True"
  5. Android: maxwidth="42dp"
  6. Android: maxheight="42dp"
  7. Android: scaletype="Fitcenter"
  8. Android: layout_marginleft="3dp"
  9. Android: SRC="@ Drawable/icon"
  10. />

<Imageview Android: Id = "@ + ID/image_view" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: adjustviewbounds = "true" <br/> Android: maxwidth = "42dp" <br/> Android: maxheight = "42dp" <br/> Android: scaletype = "fitcenter" <br/> Android: layout_marginleft = "3dp" <br/> Android: src = "@ drawable/icon" <br/>

 

KeyCode:

Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: adjustviewbounds = "true"
Android: maxwidth = "42dp"
Android: maxheight = "42dp"

 

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.