How to draw content behind parent View in Custom ViewGroup

I am using this ArcMenu https://github.com/daCapricorn/ArcMenu

Please check the code and the image of the ArcMenu on the github page

This custom view is arranged this way -> ArcMenu[View] has Children -> ArcLayout[ViewGroup] has children -> ImageViews (to hold the icons for menu)

I am trying to draw colored arc behind the Arclayout. I am doing this in the onDraw

protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub

    if(isExpanded()){
        Log.d("ArcLayout","onDraw(Canvas)");
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(colorOne);
            paint.setAlpha(125);

            canvas.drawArc(rect, startAngle, sweepAngle, true, paint);
            //Dimensions of rect are set in OnMeasure 
    }
    super.onDraw(canvas);
}

Now the problem is that the OnDraw gets called for all the children and the logic for drawing is same for the parentView and children view. I want the Colored Arc to be drawn behind the parent view and not the children(Imageviews).

Rect dimensions are top=0, left=0, right=getMeasuredWidth(), bottom=getMeasuredHeight().

When the call to canvas.onDraw is made, top Left of the rect becomes relative to child ie 0,0 of the child and the not the parent. The result is a colored arc behind the child and not the parent.

How should I ensure that the colored arc gets drawn behind the Parent view only?

链接地址: http://www.djcxy.com/p/31452.html

上一篇: Android Matrix显示不正常,我该如何解决?

下一篇: 如何在自定义ViewGroup中的父视图后面绘制内容