Android App Development Knowledge Summary

Source: Internet
Author: User

Android Knowledge Summary

This is a summary of knowledge, so there is no detailed explanation.

I. Resolution
DP length in Android, SP font usage, px pixels, in Inch, pt inch 1/72, mm mm

Understanding DP First know that density,density is an abstract unit, the density value represents the number of display points per inch, and the resolution is two concepts
QVGA screen density=120 QVGA (240*320)
HVGA screen density=160 HVGA (320*480)
WVGA screen density=240 WVGA (480*800)
WQVGA screen density=120 WQVGA (240*400)

In that conversion factor, the conversion factor is the ratio of two different screen density. For example: WVGA screen turn QVGA screen, is 120/240. With this conversion factor can be displayed on different screens of the length of the.

The screen is generally divided into the status bar, the title bar and the control area.


Resources that use HDPI tags when the screen is density=240

Resources that use MDPI tags when the screen is density=160

Resources that use LDPI tags when the screen is density=120

Resources that use XHDPI tags when the screen is density=320

Resources that use XXHDPI tags when the screen is density=480


Two. Touch event mechanism
1.ViewGoup has three events ontouchevent event handling dispatchtouchevent Event distribution Onintercepttouchevent event interception
2.view has two event ontouchevent event handling dispatchtouchevent event distribution
3. The topmost Viewgoup distributes the event to the bottom view, and the bottom view shows whether the parent class's view consumes this event by returning the value
4. In fact the touch event value responds to the Action_down event (the view that returns true is the real consumption of the Motionevent event before it responds to Action_up and Action_move)
The other event distribution principle is the same

When we understand the mechanism of this event distribution, we can solve a lot of problems.

1. Why has the ListView introduced a sliding menu function that the ListView cannot scroll?
The function of the swipe menu is achieved by registering a touch event with the ListView. If you return true after you have processed the sliding logic in the Ontouch method, the scroll event of the ListView itself is masked and naturally cannot be slid (the principle is not clickable with the button in the previous example), so the solution is to return false in the Ontouch method.

2. Why do pictures in a picture Carousel use button instead of ImageView?
The button is used in the picture carousel, mainly because the button is clickable, and ImageView is not clickable. If you want to use ImageView, there are two ways to change it. First, return true in ImageView's Ontouch method, which guarantees that all other actions after the Action_down can be executed to achieve the effect of the picture scrolling. Second, add a android:clickable= "true" attribute to ImageView in the layout file so that ImageView becomes clickable, even if Ontouch returns False,action_ Other actions after down can also be performed.

Three. The view's drawing process

The drawing of view is divided into three steps, the Onmeasure,onlayout,ondraw view is drawn first to calculate the size, then the layout coordinates, and the final draw.

1.onMeasure calculation size, there are two parameters, respectively, widthmeasurespec,heightmeasurespec these two parameters. Each measurespec has a size (s ize) and a pattern (mode), so the Widthmeasurespec and Heightmeasurespec are split. The size of the view is controlled by both the parent class and its own

There are three types of mode
Exactly the parent class determines the size of the child class
At_most maximum size of a parent class-qualified subclass
UNSPECIFIED the parent class does not have to be restricted to subclasses, how big the subclass needs to be
After the 2.onMeasure has been calculated, the layout onlayout,onlayout will return coordinates so that it can be drawn in the specified place, onlayout in ViewGroup. You can control the child view.

3.onDraw is the drawing, will return a canvas, want to draw what to draw what.

Knowing the drawing process of view, you can implement various requirements by overriding the control or customizing the control.


Four. Handler, Looper's understanding

First of all, understand the four concepts

Looper: Continuously extracts message execution from the MessageQueue. Therefore, a MessageQueue needs a looper.

Message: Messages that contain the message ID, the message Processing object, and the processed data are queued by MessageQueue and processed by handler.

Handler: Handler, responsible for sending and processing the message. When using handler, you need to implement the Handlemessage (Message msg) method to process a specific message, such as updating the UI.

MessageQueue: Message Queuing, which holds messages sent by handler and executes according to FIFO rules. Of course, storing a message is not a meaningful preservation, but rather a concatenation of the message in the form of a linked list, waiting for the looper to be extracted.

The Prepare method in Looper can be used to create a looper on the thread, if more than one looper throws an exception. The UI thread has a looper by default. Using the handler send method, you can put a msg,looper.loop () in the message queue. This method is a message loop, and a while loop keeps going to the message queue MessageQueue get MSG. The dispatchmessage,dispatchmessage through the callback handler will give Handlecallback or Handlemessage. This enables the communication between threads.

If you want to understand the details, Baidu has a lot of information.


Five. Android cross-process communication

1. Broadcast and content Provider, here slightly.
2.aidl
The use of aidl, a process as a server, a program as a client. Communication between them through the service. The server provides the calling interface, the client-bound service, and the method that invokes the server. Aidl supports normal data types, other data types are serialized and inherit parcelable.
3. Shared UserID
The security mechanism for Android comes from LUnix, which is managed through UserID permissions, such as Root,system and normal permissions. Then there was a seandroid. As long as you share the UserID, communication can be made between different applications. Shared UserID must be signed as consistent.

Android App Development Knowledge Summary

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.