Android:路径中的模糊 ShapeDrawable
Android: Blurred ShapeDrawable from a Path
我正在尝试制作 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)
它会完美地工作:/
如果你能帮助我,我将不胜感激!
您的 shapedrawable 应该覆盖 onBoundsChange() 并根据边界创建一个新的 PathShape。使用 setShape() 将新的 PathShape 应用于您的 shapedrawable
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()));
}
};
我正在尝试制作 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)
它会完美地工作:/
如果你能帮助我,我将不胜感激!
您的 shapedrawable 应该覆盖 onBoundsChange() 并根据边界创建一个新的 PathShape。使用 setShape() 将新的 PathShape 应用于您的 shapedrawable
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()));
}
};