当前位置:操作系统 > 安卓/Android >>

Android显示系统之View与Su易做图ceView更新屏幕的区别

/********************************************************************************************
 * author:conowen@大钟                                                                                                                         
 * E-mail:conowen@hotmail.com                                                                                                            
 * http://blog.csdn.net/conowen                                                                                                             
 * 注:本文为原创,仅作为学习交流使用,转载请标明作者及出处。     
 ********************************************************************************************/

1、View

View
extends Object
implements Drawable.Callback KeyEvent.Callback AccessibilityEventSource
java.lang.Object
   ↳ android.view.View
Known Direct Subclasses(直接子类,Su易做图ceView是View的子类)
AnalogClock,ImageView,KeyboardView,MediaRouteButton,ProgressBar, Space, Su易做图ceView, TextView, TextureView, ViewGroup, ViewStub
Known Indirect Subclasses(间接子类)
AbsListView,AbsSeekBar,AbsSpinner,AbsoluteLayout,AdapterView<T extends Adapter>,AdapterViewAnimator,AdapterViewFlipper,AppWidgetHostView, AutoCompleteTextView, Button, CalendarView, CheckBox, CheckedTextView, Chronometer, and 53 others.
Class Overview
This class represents the basic building block for user inte易做图ce components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class forwidgets, which are used to create interactive UI components (buttons, text fields, etc.). TheViewGroup subclass is the base class forlayouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.
View类为用户界面提供了最基础的组件,View类组件负责更换屏幕与处理事件。同时,View类也是widgets类的基础类,widgets类可以创建基础的UI组件,如Bottons、Textview等等。View类的其中一个直接子类ViewGroup是layous的基础类,layous是用来装载View或者其他的ViewGrous的,并且可以定义这些装载内容的特性。


2、
          从上述的Overview可知,Su易做图ceView是继承于View类的,(GLSu易做图ceView是继承于Su易做图ceView的)。关于Su易做图ceView的详细可以参看之前的博文
http://blog.csdn.net/conowen/article/details/7821409
Android更新屏幕主要有两种方式,继承Su易做图ceView实现Su易做图ceHolder.callback接口来实现屏幕的更新。
或者直接继承View类,复写OnDraw方法实现更新屏幕。
事实上,两种是用本质的区别的。

3、View与Su易做图ceView更新屏幕的区别

对于Su易做图ceView更新屏幕,是在非UI线程(主线程)中更新的。而对于View,则是在UI的主线程中更新画面。
那在UI的主线程中更新画面很容易造成主线程的堵塞,造成程序的长时间无响应,当主UI线程超过5秒钟没有响应用户的操作,Android系统会提示是否关闭应用程序。

当使用Su易做图ceView 来更新画面的话,就不必担心堵塞主UI线程这个问题了。但是这也带来了另外一个问题,线程的同步性。

所以当更新操作说花的时间较长,而且数据量较大的话,一般采用Su易做图ceView方式更新屏幕,而少用View。

4、Demo程序
[java] 
/*
 * author: conowen
 * e-mail: conowen@hotmail.com
 * date  :  2012.8.8
 */ 
package com.conowen.viewtestdemo; 
 
import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.graphics.RectF; 
import android.view.View; 
 
public class MyView extends View { 
 
    private int counter; 
 
    public MyView(Context context) { 
        super(context); 
        // TODO Auto-generated constructor stub 
    } 
 
    @Override 
    protected void onDraw(Canvas canvas) { 
        // TODO Auto-generated method stub 
        super.onDraw(canvas); 
/*      synchronized (this) {
            try {
                wait(10 * 1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
*/ 
        // 设定Canvas对象的背景颜色 
        canvas.drawColor(Color.YELLOW - counter); 
 
        // 创建画笔 
        Paint p = new Paint(); 
        // 设置画笔颜色 
        p.setColor(Color.RED); 
        // 设置文字大小 
        p.setTextSize(40); 
        // 消除锯齿 
        p.setFlags(Paint.ANTI_ALIAS_FLAG); 
 
        // 在canvas上绘制rect 
        canvas.drawArc(new RectF(100, 50, 400, 350), 0, counter, true, p); 
        if (counter == 400) { 
          &nbs

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,