Project Essay Size series: Px,sp,dp;java set Size (layoutparams)

Source: Internet
Author: User

Essay One:

PX: The simplest understanding of physical pixels. Before the rpx of the front end is 1:2 of the relationship, subconsciously think that PX and DP is a 2:1 relationship, it is not, and because of the number of Android devices, so it is based on the resolution to remember.

DP: To be detailed in detail; first, simply record the presence of the DP to ensure that the components appear in roughly the same visual size on phones with different resolutions. The clearer the screen resolution, the higher the 1DP contains the more pixels that are equal to more px.

SP: the size of the font varies with the size of the screen, depending on the size of the system, which is small and large.

Essay Two:

In general, depending on the model of the different screen size is also sometimes to be based on the screen size of the corresponding high-width settings. This can be done in Java:

Viewgroup.layoutparams recycleviewparams =  mrecommandgrid.getlayoutparams ();         if (recycleviewparams!=null) {            int mpadding = densityutil.dip2px (GetContext (), ten);             int mscreenheight = getcontext (). Getresources (). Getdisplaymetrics (). heightpixels;             int mscreenwidth = getresources (). Getdisplaymetrics (). Widthpixels;            Recycleviewparams.height  = MSCREENHEIGHT/4;             = mscreenwidth-2*mpadding;            Mrecommandgrid.setlayoutparams (recycleviewparams);}

Project Essay Size series: Px,sp,dp;java set Size (layoutparams)

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.