I'm trying to draw custom UI (a path in this case) on top of a Gallery. I've extended the base Gallery class and overwritten the draw method like this:
public class MyGallery extends Gallery {
...
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(mPath, mPaint);
}
I thought that putting my path drawing after super.onDraw
would make sure that the path was drawn on top of the gallery AND it's child views, but instead the child views are layered on top of my path.
Does anyone know how to draw this properly?
(I know I could include a RelativeLayout and layer a further view to draw my path on top of the Gallery that way, but I'd rather keep it all in one class)
I found this straight after asking, so decided to post anyway in case someone has the same issue. To draw over child views in a Gallery, overwrite dispatchDraw
instead of onDraw
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.drawPath(mPath,mPaint);
}
来源:https://stackoverflow.com/questions/11054214/custom-drawing-on-top-of-gallery-view-and-its-child-views