Custom drawing on top of Gallery view (and it's child views)

不问归期 提交于 2019-12-07 20:43:19

问题


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)


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!