Android的绘图按钮,自定义视图以帆布? [英] Android drawing button to canvas with custom view?

查看:125
本文介绍了Android的绘图按钮,自定义视图以帆布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能借鉴自定义视图画布顶部的按钮? (preferably上的中部右侧)有什么事我都做button.draw(画布)之前调用?

How can I draw a button on top of the canvas in a custom view? (Preferably on the mid-right side) Is there something I have to call before doing the button.draw(canvas)?

    public class MyClass extends View {
    public Simulation(Context context) {
            super(context);
            pauseButton.setText("TestButton");
            pauseButton.setClickable(true);
            pauseButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            Log.i(TAG, "Button Pressed!");
            }
            });
    public onDraw(Canvas canvas) {
           super.onDraw(canvas);
           pauseButton.draw(canvas);
    }
    }

感谢您的时间

推荐答案

您不能插入一个按钮到画布上。 Canvas是位图或视图的位图缓存的接口。你可以只画等位图或像素它,而不是插入的对象或部件。

You cannot insert a button into canvas. Canvas is an interface for bitmap or a bitmap buffer for a view. You can only draw other bitmap or pixels in it, not insert an object or a widget.

有一些解决方案:


  1. 作为尼古拉建议,使用的FrameLayout 并创建两个层(视图),第一您的自定义视图和第二LinerView或RelativeView,这会在顶部,在那里你可以有按钮等等

  1. as Nikolay suggested, use a FrameLayout and create two layers (views), first your custom view and the second LinerView or RelativeView, which will come on top, where you can have buttons etc

在画布上绘制一个buttun的图像,然后使用 onTouchEvent 在自定义视图和测试用于触摸的坐标,然后做一些事情......为onTouchEvent这里一个例子:<一个href=\"http://stackoverflow.com/questions/5368774/make-certain-area-of-bitmap-transparent-on-touch/5439357#5439357\">Make位图触摸透明的特定区域

draw an image of a buttun on Canvas then use onTouchEvent in your custom view and test for the coordinates of the touch, then do something... an example for onTouchEvent here: Make certain area of bitmap transparent on touch

这篇关于Android的绘图按钮,自定义视图以帆布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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