"First line code--android" The interface design of reading notes

Source: Internet
Author: User

1. Unit DP, DIP, SP, PT, PX, in, MM

Here is a reference to a solution on StackOverflow:

    • px is one pixel.
    • sp is scale-independent pixels.
    • dip is density-independent pixels. (Dip = = DP is ture)
The differenceDP
Density-independent Pixels-an Abstract unit that's based on the physical Density of the screen. These units is relative to a in DPI screen, so one DP was one pixel on a in the DPI screen. The ratio of dp-to-pixel would change with the screen density, but not necessarily in direct proportion. Note:the compiler accepts both "Dip" and "DP", though "DP" is more consistent with "SP". That is: dp=160*px/dpiSP
Scale-independent Pixels-this is the same as the DP unit, but it's also scaled by the user ' s font size preference. It is recommend the if specifying font sizes, so they would be a adjusted for both the screens density and use R ' s preference. Remenber this:

would use

    • spFor font sizes
    • dipFor everything else
To make it absolutely clear-try to never use anything but SP or DP unless you absolutely has to. Using SP/DP would make your Android applications compatible with multiple screen densities and resolutions.2. Visibility of invisible and goneInvisible: Control disappears, click event expires, still occupy position gone: control disappears, layout position is vacated3. Set the progress bar styleSet to Horizontal: style= "? Android:attr/progressbarstylehorizontal"4.LinearLayoutTo set a EditText and button on a line, let the button width wrap the content so that EditText occupies the remaining width of the screen<edittext
android:id= "@+id/input_message" android:layout_width= "0DP" android:layout_height= "wrap _content" android:layout_weight=" 1 " android:hint=" Type Something "
/><button
android:id= "@+id/send" android:layout_width= "wrap_content" android:layout_height= "wrap _content " android:text=" Send "
/> 5. A simple quick ListView that displays a batch of stringprivate string[] data = {"Apple", "Banana", "Orange", "Watermelon","Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango"};@Overrideprotected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); arrayadapter<string> adapter = new Arrayadapter<string> ( mainactivity.this, Android. R.layout.simple_list_item_1, data); ListView ListView = (ListView) Findviewbyid (R.id.list_view); Listview.setadapter (adapter);
}  6. Custom Adapter The role of the overloaded GetView () methodThis method is called when each subkey is scrolled into the screen7.ListView Performance OptimizationUse the parameter Convertview of the GetView () method in adapter to avoid every time the layout file is repeatedly loaded using Viewholder to record the bound control ID and the control instance8. Write Chat interface mode selectionUse a layout to store outgoing and outgoing message bubbles, which is better than using multiple layout files in a way that sets control visibility based on message flow

"First line code--android" The interface design of reading notes

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.