I understand the view on Android and iOS

Source: Internet
Author: User

View, which is almost the base class in all interface systems, is UIView in iOS and is view on Android. So, what is view, what he did, how he did it, in this article, I hope to bring you some inspiration.

Abstract

View is actually an abstract class that is responsible for abstracting rendering, layout, and touch events.

Rendering abstraction

We know that whether it's IOS or Android, their rendering engine is OPENGL,OPENGL for C (and, of course, it's packaged in both Objective-c and Java). As a front-end developer, the interface is written directly using OpenGL, which is not (Tai) present (Nan) real (Le). So, we have the interface library, this interface library, on iOS, what we call Uikit, on Android, we use the android.view.* package. Whether iOS or Android, the interface library to do things, the goal is consistent, that is, the interface rendering from concrete to abstract.

Layout abstraction

Layout, which is the most important feature of view, such as hierarchical control, rectangle size, matrix transformation, is the category of layout abstraction, layout is the basis of rendering, touch, the lack of layout, rendering and touch can not continue.

Touch Event Abstraction

In addition to rendering and layout, view also has to assume another responsibility ———— touch. The so-called touch, touch control, on the one hand, view to receive touch events, on the other hand, the view is responsible for feedback received touch events, as for the specific touch implementation, the following will be described in detail.

Rendering

In general, view is not encapsulated directly for OpenGL, but through the middle tier, on iOS, with Calayer (Coregraphics), and on Android, using Canvas (Skia).

Ios

On iOS, each uiview has a corresponding calayer, which we call layer-back, which means that all uiview properties, eventually, will be set to Calayer.

Why use the middle tier of Calayer? It is important that the COREGRAPHCIS framework, which existed at the beginning of the next system creation, is the core framework of the entire MacOS system. So 6 of the frame, for Mao wouldn't let him transplant to iOS? So, Calayer is logically become uiview behind the Yin HelpMate. UIView will proxy the following properties to Calayer

    • Alpha

    • Frame

    • BackgroundColor

    • Clipstobounds

    • Hidden

So few properties for hair? Well, because the other properties need to be set on your own calayer. What the? You want to ask how calayer is rendered to the screen? Check it yourself, it is said that a special book is written in this. In general, UIView in the rendering, and did not do anything magical things, Calayer is the one who has been working silently.

Android

Android is actually a grassroots system, when born, and not a rich dad ... So? The rendering layer of Android view is actually copied from the canvas in H5.

For example, I'm going to draw a black backgroundcolor on the View and actually void onDraw(Canvas canvas) execute the following code in the method.

For example, I want to make the view have rounded corners to cut the effect, how to do? Actually, it does.

Jiangzi, all the patterns drawn in this view, including the child view, are clipped by a path.

So, what did the view do? View actually defines x, y, width, height only if you know these parameters, you can draw a background color, otherwise ... You draw an egg? The view also manages properties such as Alpha/backgroundcolor, which you can find in the canvas and paint classes for related parameters.

IOS VS Android

This, there is no good contrast, nothing more than the abstraction of the rendering layer is not the same. In terms of rendering performance, iOS is a better one, since the introduction of Android 4.x Skia, especially Skia after the Google butter program, Android rendering performance is not much worse. If you die to compare, I can only say one is Calayer, one is canvas,calayer more abstract.

78486699

I understand the view on Android and iOS

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.