Android的自定义绘制对象范围 [英] Android Custom Drawable bounds
本文介绍了Android的自定义绘制对象范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写一个自定义绘制对象,在一个位图文字:
I'm write a custom Drawable, a text over a bitmap:
@Override
public void draw(Canvas canvas) {
canvas.drawBitmap(badge, matrix, null);
canvas.drawText(count, size / 2, size / 2 + (text_size) / 2 , p);
}
当我用我的绘制在ImageView的,它的罚款。
When I use my drawable in an imageView, it's fine.
但是,如果我用这个有一个TextView(化合物绘)这是alignement是错误的。
But if I use this with a textview (compound drawable) it's alignement is wrong.
我都尝试setCompoundDrawablesWithIntrinsicBounds和setCompoundDrawables
I tried both setCompoundDrawablesWithIntrinsicBounds and setCompoundDrawables
同样的结果,我错过了什么?
Same results, what did I miss ?
感谢。
推荐答案
我设法得到右对齐(我是绘制一个圆/平方米这么宽==高):
I manage to get the right alignment (my drawable is a circle/square so width == height):
在我Custom_Drawable构造函数:
In my Custom_Drawable ctor:
Custom_Drawable(int size) {
this.size = size;
}
的onDraw方法:
onDraw method:
@Override
public void draw(Canvas canvas) {
// draw here
setBounds(0, 0, this.size, this.size);
}
在设置绘制:
b.setCompoundDrawables(new Custom_Drawable(25), null, null, null);
这篇关于Android的自定义绘制对象范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文