我想画出具体的Line
,Rectangle
或者Bitmap
使用Canvas
. 如果我在位图上绘制,它也会采用方形空背景。
所以我只想画出那个特定的Bitmap
区域。
我想画出具体的Line
,Rectangle
或者Bitmap
使用Canvas
. 如果我在位图上绘制,它也会采用方形空背景。
所以我只想画出那个特定的Bitmap
区域。
从您想要的图像中创建一个名称为“bmp1”的位图
创建一个自定义视图
创建一个类并像这样扩展视图
class MyCustomView extends View{
private Rect m_ImageRect;
private Rect m_TextRect ;
//you need these constructor
//you can init paint object or anything on them
public MyCustomView (Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
m_Context = context;
}
public MyCustomView (Context context, AttributeSet attrs)
{
super(context, attrs);
m_Context = context;
}
public MyCustomView (Context context)
{
super(context);
m_Context = context;
}
//then override on draw method
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//here frist create two rectangle
//one for your image and two for text you want draw on it
m_ImageRect = canvas.getClipBounds();
m_TextRect = canvas.getClipBounds();
//it gives you an area that can draw on it,
//the width and height of your rect depend on your screen size device
canvas.drawBitmap(your bitmap(bmp1), null, m_ImageRect , paint);
canvas.save();
canvas.clipRect(m_TextRect);
canvas.drawText("your text", the x position you want to start draw,
the y position you want to start draw, m_paintText);
canvas.restore();
}
}
最后将自定义视图放在您的布局上,并在其上设置字段以将值发送到视图以绘制您想要的所有内容
我希望它对你有所帮助,如果这不是你想要的!
发布您的代码,也许我可以为您提供更多帮助
好像你需要剪辑。参见示例:http ://www.example8.com/category/view/id/15543 ,了解 Android 画布裁剪, http: //jtomlinson.blogspot.com/2008/10/clipping.html
通过剪辑,您可以指定哪些区域应该是“可编辑的”。