Android中View绘制过程(六) performDraw
2017-06-19 11:28
387 查看
performTraversals()中执行了performmeasure确定了每一个View的width,和height, 就会调用performLayout,确定这些View在屏幕
的位置,调用performDraw()在每一个View将图像画在屏幕上自己layout确定的位置上就可以了。
调用如下performDraw()->draw()->drawSoftware()->从DecorView开始递归调用绘制,代码如下:
mView.draw(canvas);
ViewGroup,FrameLayout中都没有重写此方法,回到View中查看,View中代码也好长,关键是调用了一个diapatchDraw(),在ViewGroup中
重写了这个方法,关键点在于
for (int i = 0; i < childrenCount; i++) {
while (transientIndex >= 0 && mTransientIndices.get(transientIndex) == i) {
final View transientChild = mTransientViews.get(transientIndex);
if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE ||
transientChild.getAnimation() != null) {
more |= drawChild(canvas, transientChild, drawingTime);
}
transientIndex++;
if (transientIndex >= transientCount) {
transientIndex = -1;
}
}
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
more |= drawChild(canvas, child, drawingTime);
}
}
遍历自己的chlidView一次调用DrawChlid,这个方法如下
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
return child.draw(canvas, this, drawingTime);
}
调用Chlid中的额draw方法,
draw方法会调用onDraw这个回调,在这个回调中可以自定义View的绘制。终于自上而下完成View的绘制。
其他说明draw方法的说明如下:
/*
* Draw traversal performs several drawing steps which must be executed
* in the appropriate order:
*
* 1. Draw the background
* 2. If necessary, save the canvas' layers to prepare for fading
* 3. Draw view's content
* 4. Draw children
* 5. If necessary, draw the fading edges and restore layers
* 6. Draw decorations (scrollbars for instance)
*/
第一步,Draw the background是发生在onDraw之前的,还有剩下的一些画布的处理,应该注意相对回调onDraw的先后的顺序。
的位置,调用performDraw()在每一个View将图像画在屏幕上自己layout确定的位置上就可以了。
调用如下performDraw()->draw()->drawSoftware()->从DecorView开始递归调用绘制,代码如下:
mView.draw(canvas);
ViewGroup,FrameLayout中都没有重写此方法,回到View中查看,View中代码也好长,关键是调用了一个diapatchDraw(),在ViewGroup中
重写了这个方法,关键点在于
for (int i = 0; i < childrenCount; i++) {
while (transientIndex >= 0 && mTransientIndices.get(transientIndex) == i) {
final View transientChild = mTransientViews.get(transientIndex);
if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE ||
transientChild.getAnimation() != null) {
more |= drawChild(canvas, transientChild, drawingTime);
}
transientIndex++;
if (transientIndex >= transientCount) {
transientIndex = -1;
}
}
final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) {
more |= drawChild(canvas, child, drawingTime);
}
}
遍历自己的chlidView一次调用DrawChlid,这个方法如下
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
return child.draw(canvas, this, drawingTime);
}
调用Chlid中的额draw方法,
draw方法会调用onDraw这个回调,在这个回调中可以自定义View的绘制。终于自上而下完成View的绘制。
其他说明draw方法的说明如下:
/*
* Draw traversal performs several drawing steps which must be executed
* in the appropriate order:
*
* 1. Draw the background
* 2. If necessary, save the canvas' layers to prepare for fading
* 3. Draw view's content
* 4. Draw children
* 5. If necessary, draw the fading edges and restore layers
* 6. Draw decorations (scrollbars for instance)
*/
第一步,Draw the background是发生在onDraw之前的,还有剩下的一些画布的处理,应该注意相对回调onDraw的先后的顺序。
相关文章推荐
- android绘制view的过程(自定义view一)
- Android绘制View的过程研究——计算View的大小
- android view的绘制过程
- android绘制view的过程(自定义view一)
- 【转】android绘制view的过程之一---------计算view大小
- Android中的View与ViewGroup绘制过程,手势监听顺序与使用
- Android View绘制过程
- Android View绘制过程
- 【Android】View绘制过程分析之layout
- Android绘制View的过程研究——计算View的大小
- android:绘制view过程学习记录
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例
- Android绘制View的过程研究——计算View的大小
- android 中view的绘制过程
- Android_View的绘制过程
- android界面View简介及android界面绘制过程
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- Android绘制View的过程研究——计算View的大小
- Android View绘制过程
- Android的View绘制过程,onMeasure()方法介绍