Known Direct Subclasses(直接子類,SurfaceView是View的子類) AnalogClock,ImageView,KeyboardView,MediaRouteButton,ProgressBar,Space,SurfaceView,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 interface 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.
08-08 15:33:34.587: E/AndroidRuntime(4995): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
這兩個方法只是再次調用onDraw方法而已。
Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
如下面的代碼所示。這樣的話,就不必擔心主UI線程被堵塞了。
[java] view plaincopyprint?
/*
* author: conowen
* e-mail: conowen@hotmail.com
* date? :? 2012.8.4
*/?
package com.conowen.viewtestdemo;?
?
import java.util.Timer;?
import java.util.TimerTask;?
?
import android.content.Context;?
import android.graphics.Canvas;?
import android.graphics.Color;?
import android.graphics.Paint;?
import android.graphics.RectF;?
import android.view.View;?
?
publicclass MyView extends View {?
?
??? privateint counter;?
??? privateboolean isNewThread;?
??? private RectF rectf;?
??? private Paint p;?
??? private Timer timer;?
?
??? public MyView(Context context) {?
??????? super(context);?
??????? // TODO Auto-generated constructor stub?
??????? isNewThread = true;?
??????? rectf = new RectF(100, 50, 400, 350);?
??????? p = new Paint();?
??????? timer = new Timer();?
??? }?
?
??? publicvoid newThread() {?
?
??????? timer.schedule(new TimerTask() {?
?
??????????? @Override?
??????????? publicvoid run() {?
??????????????? // TODO Auto-generated method stub?