2

I am trying to make a ShapeDrawable but when I resize it, Android draws a blurred line. I know that some example codes say this doesn't happen, so I can't understand what I am doing wrong. This is what I wrote:

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); 

If I write miImagen.setBounds(0,0,50,50) it works perfectly :/ I'll be grateful if you could help me!

NG_
  • 6,895
  • 7
  • 45
  • 67
Diego Garcia
  • 555
  • 2
  • 6
  • 20

1 Answers1

2

your shapedrawable should override onBoundsChange() and create a new PathShape based on the bounds. Use setShape() to apply the new PathShape to your 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()));

        }
    };
dangVarmit
  • 5,641
  • 2
  • 22
  • 24