Android.util.TypedValue.applyDimension

Source: Internet
Author: User

Let's look at an example:

int size = (int) typedvalue.applydimension (Typedvalue.complex_unit_dip, 3, Context.getresources (). Getdisplaymetrics ( ));

This line of code converts the value of dip 3 to the PX value in the current screen resolution state

Here is an introduction to the API:

Public static float applydimension (int unit, float value, displaymetrics metrics) SINCE:API Level 1

Converts an unpacked complex data value holding a dimension to it final floating point value. The parameters and is as in unit value TYPE_DIMENSION .

Parameters
Unit The unit to convert from.
Value The value to apply the unit to.
Metrics Current display metrics to use the conversion--supplies display density and scaling information.
Returns
    • The complex floating point value multiplied is the appropriate metrics depending on its unit.

View its source code in the framework

     Public Static floatApplydimension (intUnitfloatvalue, Displaymetrics metrics) {        Switch(unit) { Casecomplex_unit_px:returnvalue;  CaseComplex_unit_dip:returnValue *metrics.density;  Casecomplex_unit_sp:returnValue *metrics.scaleddensity;  Casecomplex_unit_pt:returnValue * metrics.xdpi * (1.0f/72);  Casecomplex_unit_in:returnValue *metrics.xdpi;  Casecomplex_unit_mm:returnValue * metrics.xdpi * (1.0f/25.4f); }        return0; }

If the incoming UNIT is compliex_unit_px, the return value is consistent with the value passed in, and the inverse is converted to PX and returned according to a certain calculation.

Android.util.TypedValue.applyDimension

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.