简体   繁体   English

“图库”视图(及其子视图)顶部的自定义图形

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

I'm trying to draw custom UI (a path in this case) on top of a Gallery. 我试图在图库顶部绘制自定义UI(在这种情况下为路径)。 I've extended the base Gallery class and overwritten the draw method like this: 我扩展了基础Gallery类,并覆盖了draw方法,如下所示:

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. 我认为将路径绘制放在super.onDraw之后可以确保路径绘制在图库顶部,并且是子视图,但子视图位于我的路径上。 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) (我知道我可以包括一个RelativeLayout并在视图上分层放置一个新视图,以这种方式在Gallery顶部绘制路径,但我宁愿将其全部放在一个类中)

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 要在Gallery中绘制子视图,请覆盖dispatchDraw而不是onDraw

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    canvas.drawPath(mPath,mPaint);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM