在对话框中绘制图表
我有一个概念性问题要问:
我创建了一个自定义对话框(扩展对话框),我想在对话框的前三分之一处绘制一个图表(动态数据,而不是静态)。
解决这个问题的最佳(唯一?)方法是什么?
A) 在对话框中获取画布并在其上绘图?似乎我需要访问对话框的绘图,是的,或者我可以在绘图之外执行此操作吗?
B)在对话框布局(例如LinearLayout)中子类化视图并覆盖它的绘制并绘制图表?
C) 其他?我读过一种方法是绘制位图,然后 blt (或等效方法)到画布。这听起来更接近我想要做的,因为一旦我创建了图表,我就不需要更改它(没有直接的用户交互)。
我还没有找到任何好的示例代码来处理对话框中的自定义绘图,所以如果我遗漏了一些东西,一个例子就很好了。
非常感谢,
里奇
I have a conceptual question to ask:
I created a custom dialog (extends Dialog) and I want to draw a chart (dynamic data, not static) in the top third of the dialog.
What's the best (only?) way to approach this?
A) Get a canvas to the dialog and draw to it? Seems like I need access to the dialog's draw, yes, or can I do this outside of the draw?
B) Subclass a view within the dialog layout (e.g. LinearLayout) and override it's draw and draw the chart?
C) Other? I've read that one approach would be to draw to a bitmap and then blt (or equivalent) to the canvas. This sounds closer to what I want to do, as once I create the chart, I have no need to alter it (no direct user interaction).
I haven't yet found any good sample code that deals with custom drawing in a dialog, so if I'm missing something, an example would be great.
Thanks much,
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。
我的解决方案是上述 B/C 的混合。由于我需要访问视图的draw() 方法,因此我创建了自己的ImageView 子类(例如MyView)。
从 draw() 中,我可以获得出现在对话框中的 ImageView 的动态大小。给定大小,我现在可以在对话框中执行缩放到自定义 ImageView 大小的绘制。
我必须记住在对话框布局中使用正确的自定义视图 XML 语法(例如“com.avaliant.dialogtest.MyView”来替换“ImageView”)。当然,在我的对话框类中,我必须将视图设置为正确的视图类:
一旦我理解了为什么我必须做我必须做的事情,就很容易了:)。
富有的
Solved.
My solution was a hybrid of B/C above. Since I needed access to the view's draw() method, I created my own subclass of an ImageView (e.g., MyView).
From within the draw(), I can get the dynamic size of the ImageView as it appears in the dialog. Given the size, I can now perform draws scaled to the custom ImageView size within the dialog.
I had to remember to use the proper custom view XML syntax in the dialog layout (e.g. "com.avaliant.dialogtest.MyView" to replace "ImageView"). And, of course, in my dialog class, I had to set to view to the proper view class:
Quite easy once I understood WHY I had to do what I had to do :).
Rich