Android framework review sp and wp sp objectsUse MediaPlayer to describe the implementation of sp. Sp is a template class, and T is a subclass of RefBase. Sp can be used for any class inherited from RefBase. The binder class also
becomes a candidate object for garbage collection, just like there are no remaining references, and once the object is deleted, all weak references will also be clear. Weak references are suitableDataA class with many Members and relatively easy re-creation, also known as the fat class, can reference objects by creating weak references, but does not prevent it from being recycled by garbage collection, achieve a certain balance in memory usage.
In Android
With Cocos2d-x 3.4 developed a small game, and then successfully access the Baidu Alliance ads, many beginners also want to develop the game in their own access to advertising profits, so I will Baidu Alliance banner and interstitial ads for example, according to their own access to the steps to do a summary, I hope that the need for developers to help.First, Baidu SDK package Import and configuration of pe
From the start of the Android program, I was told that the common sense
1. Length width of the value to use the DP as a unit into the Dimens.xml file
2. The value of the font size to use the SP as a unit, also into the Dimens.xml file
Then, there is no then, as if the subtext is that, you remember to use on the line.
One day, when we accidentally put the font into a DP, it can work, and the effect of th
When writing code in Android native, it is often exposed to sp and wp. sp does not mean smart pointer, but strong point; wp is weak pointer. These two concepts are similar to the strong and weak references in JAVA. Using sp and wp can eliminate the need for programmers to release memory and prevent memory leakage. Let'
About android's Unit (dp, sp) and androiddp
Android is a headache.
---------Android has the following units:
Common dip and sp, sometimes using px.
---------Two classes are introduced:
TypedValue: There are some methods related to unit conversion.
DisplayMetrics:
DisplayMetrics dm = new DisplayMetrics();getWindowMan
1 "DP is a unit that is independent of pixel density, that is, in the same size, but different resolution of the phone, the thing with the DP logo, the size of the display is the same.The SP is used to identify the font, not only with respect to the screen size, but also with the system font size set.[HTML]View Plaincopy
TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="
After reading the code at the Android Framework, I can find that the ubiquitous SP has a visual impact on me. What is this? At the beginning, I think this is basically used as a pointer, and I don't know its internal beauty. So I will learn and sum up the charm of the SP class here.
1 SP this product is a template clas
= density_device/(float) density_default;Xdpi = density_device;
--------------------------Density_default = density_medium = 160;
========================================================== ====Therefore, if PT and SP take the same value of 1, the coefficient between 1pt and 1sp can be set to X,
1 * density_device/72 = x * 1 * density_device/160 = gt;X = 160/72 = 2.2222
That is to say, in Android, 1pt is r
best to use SP as the unit for textview font size and viewTextviewAndroid uses SP as the font size unit by default.
######################################## ###########################\
Conversion (using SP and Pt as an example)View the source code of textview and other classes. We can see that:
Case complex_unit_px:Return value;Case complex_unit_sp:Return Value
Shows the difference between units px and dip and SPDip:device independent pixels (device independent pixels). Different devices have different display effects, this is related to the device hardware, generally we support WVGA, HVGA and QVGA recommend this, do not rely on pixels.Px:pixels (pixels). Different devices show the same effect, generally we hvga represent 320x480 pixels, this use more.Pt:point, is a standard length unit, 1pt=1/72 inches, for the printing industry, very simple to use;sp
Dip:device independent pixels (device independent pixel). Different devices have different display effects, this is related to the device hardware, we generally support the WVGA, HVGA and QVGA recommended to use this, do not rely on pixels.px:pixels (pixel). Different devices display the same effect, generally we hvga represent 320x480 pixels, this use more.Pt:point, is a standard length unit, 1pt=1/72 inches, used in the printing industry, is very simple and easy to use;sp:scaled pixels (zoom i
Work, there will always be a task to develop a new page, the general process is the product manager to determine the page and function to develop, and then the designer to provide the design manuscript, then by our developers to complete the development work.Usually, the designer provides the design of the dimension will be very detailed, such as when it comes to words, word size, location, color, font, etc., will be one by one mark. Note that the designer offers all dimensions in px(pixels).How
compared to the difference is more obvious.
Dip
Exactly the same as DP, except the name is different. The dip was used in earlier versions of Android, and the DP name was later recommended for unification with SP.
Sp
Abstract pixels independent of scale (Scale-independent Pixel). The SP a
Comparison of pixel units dp, px, pt, and sp in androidDp (dip): device independent pixels (device independent pixel ). different devices have different display effects, which are related to the hardware of the device. We recommend that you use this function to support WVGA, HVGA, and QVGA without pixels. Px: pixels (pixels). Different devices have the same display effect. Generally, we use HVGA to represent 320x480 pixels, which is usually used. Pt:
http://blog.csdn.net/jiangwei0910410003/article/details/40509571Today started my app development, because I have been doing the SDK, so the interface UI is very few, just started to do Android applications, there is no dp,px,sp and other concepts have a deep understanding, only know their transformation, and write a conversion tool class. Android has been doing m
Today started my app development, because I have been doing the SDK, so the interface UI is very few, just started to do Android applications, there is no dp,px,sp and other concepts have a deep understanding, only know their transformation, and write a conversion tool class. Android has been doing more than a year, and now to start app development, decided not t
This article is reproduced in http://blog.csdn.net/student9128/article/details/53932470It is well known that the conversion between DP and PX,SP and PX is essential in Android development, and the following code is recorded:1 Public classDisplayutils {2 /**3 * Convert PX to its equivalent DP4 * 5 * Convert px to equal DP6 */7 Public Static intPX2DP (Context context,floatpxvalue) {8
Px, dp, sp, and androidpxdpsp used in android DevelopmentFirst, we will introduce these units:
Px: pixels (pixels), which corresponds to the actual pixels on the screen.
Dip: device independent pixels, which is a density-independent pixel. It is an abstract unit based on screen density. On a display at 160 o'clock per inch,
1dp = 1px, that is, the 1: 1 relationship. (Dp is dip)
Size Units (px, dpi, dp, dip, and sp) of the View for android Application Development, and androiddpi
I. pixel (px) and screen resolution
1) px (Pixels, Pixels): corresponds to the actual Pixels on the screen. For example, 320*480 screens have 320 pixels horizontally and 480 pixels vertically.
2) the screen resolution is the total number of physical pixels displayed on the screen. It is equal to the number
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.