我正在尝试制作ShapeDrawable
但是当我调整它时,Android会画出一条模糊的线条。我知道一些示例代码说这不会发生,所以我无法理解我做错了什么。这就是我写的:
Path pathTriangulo = new Path();
pathTriangulo.moveTo(0, 0);
pathTriangulo.lineTo(50, 0);
pathTriangulo.lineTo(50, 50);
pathTriangulo.lineTo(0, 0);
miImagen = new ShapeDrawable(new PathShape(pathTriangulo,50,50));
miImagen.getPaint().setColor(Color.BLACK);
miImagen.getPaint().setStyle(Paint.Style.STROKE);
miImagen.setBounds(0, 0, 5000, 5000);
如果我写miImagen.setBounds(0,0,50,50)
它完美无缺:/
如果你能帮助我,我将不胜感激!
答案 0 :(得分:2)
你的shapesrawable应该覆盖onBoundsChange()并根据边界创建一个新的PathShape。使用setShape()将新的PathShape应用于您的可绘制的
miImagen = new ShapeDrawable(new PathShape(pathTriangulo,50,50)) {
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
Path pathTriangulo = new Path();
pathTriangulo.moveTo(0, 0);
pathTriangulo.lineTo(50, 0);
pathTriangulo.lineTo(50, 50);
pathTriangulo.lineTo(0, 0);
setShape( new PathShape(pathTriangulo, bounds.width(), bounds.height()));
}
};