在“图库"视图(及其子视图)顶部的自定义图形 [英] Custom drawing on top of Gallery view (and it's child views)

查看:77
本文介绍了在“图库"视图(及其子视图)顶部的自定义图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Gallery顶部绘制自定义UI(在这种情况下为路径).我已经扩展了Gallery类的基本类并覆盖了draw方法,如下所示:

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);
}

我认为将路径绘制放在 super.onDraw 之后会确保路径绘制在图库顶部,并且是子视图,但是子视图位于我的顶部小路.有人知道如何正确绘制吗?(我知道我可以包括一个RelativeLayout并在视图上添加另一个视图以这种方式在Gallery顶部绘制路径,但我宁愿将其全部放在一个类中)

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)

推荐答案

我在询问后立即发现了这个问题,因此决定以任何方式发布,以防有​​人遇到相同的问题.要在图库中绘制子视图,请覆盖 dispatchDraw 而不是 onDraw

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);
}

这篇关于在“图库"视图(及其子视图)顶部的自定义图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆