我试图在 ImageView 上画一条线,但每当我尝试使用 Canvas 时,我都必须重新加载位图,这不是我的 Intent 。 有没有一种方法可以使用 Canvas 在上传的 ImageView 上简单地画一条线,而无需刷新图像?或者另一种在 Android ImageView 上画线的方法?
最佳答案
或者,如果您希望能够绘制任何线条(矩形、椭圆形等),请将 ImageView 子类化为您自己的 ImageView 并自行绘制。
public class MyImageView extends ImageView {
Paint linePaint = new Paint();
@Override
protected void onDraw(Canvas canvas) {
super.onDraw();
// And draw your line.
// (Be sure to have set the values/fields in linePaint earlier so that you draw the correct line/type/size/etc).
canvas.drawLine(0, getHeight()/2, getWidth(), getHeight()/2, linePaint);
}
}
在布局 xml 中,不要指定
关于android - 如何在 ImageView 上画线而无需重新加载它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14719715/