guodayang / androidsvg

Automatically exported from code.google.com/p/androidsvg
0 stars 1 forks source link

Scale in ImageView #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
SVGImageView doesn't properly scale the image. Even if w o h are changed, it 
seems that only takes w and preserves aspect ratio

SVGImageView siv = new SVGImageView(this);
siv.setImageResource(R.drawable.image_svg);

int w=100;
int h=100;

RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(w,h);
siv.setLayoutParams(rllp);

Original issue reported on code.google.com by thaedne...@gmail.com on 7 Jul 2014 at 10:06

Attachments:

GoogleCodeExporter commented 9 years ago
So do you mean it does enlarge, but you want it to stretch to exactly fit both 
width and height?

Keeping the aspect ratio is the default behaviour.  If you want it to do the 
stretch, try adding the following to your code:

siv.setScaleType(ScaleType.FIT_XY);

I think it should do what you want.

Original comment by paul.leb...@gmail.com on 7 Jul 2014 at 10:28

GoogleCodeExporter commented 9 years ago
For some reason, the image doesn stretch to the parameters I give it. I'd like 
the image stretch like the attachment.

Thanks

Original comment by thaedne...@gmail.com on 8 Jul 2014 at 2:51

Attachments:

GoogleCodeExporter commented 9 years ago
Hi thaenevol

Did you try my suggestion?  What happened?

Original comment by paul.leb...@gmail.com on 8 Jul 2014 at 9:06

GoogleCodeExporter commented 9 years ago
Hi. Yes. I've attached two files, one with fitxy and the other with center. It 
'cuts' the image...

Original comment by thaedne...@gmail.com on 8 Jul 2014 at 8:41

Attachments:

GoogleCodeExporter commented 9 years ago
Hi. Based on this: https://code.google.com/p/svg-android/issues/detail?id=7 I 
tried with:

public class CustomPictureDrawable extends PictureDrawable {

    private float scalex, scaley;

    public CustomPictureDrawable(Picture picture, float scalex, float scaley) {
        super(picture);
        this.scalex = scalex;
        this.scaley = scaley;
    }

    @Override
    public void draw(Canvas canvas) {
        Matrix original = canvas.getMatrix();
        canvas.scale(scalex, scaley);
        super.draw(canvas);
        canvas.setMatrix(original);
    }
}

In SVGImageView.java

But the image is still in the center.

Original comment by thaedne...@gmail.com on 9 Jul 2014 at 4:01

GoogleCodeExporter commented 9 years ago
I see the same behaviour using this XML definition:

    <com.caverock.androidsvg.SVGImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/content_desc_overlay"
        android:scaleType="fitXY"
        svgimageview:svg="@raw/thirds" />

Original comment by o...@itmaze.com.au on 3 Oct 2014 at 2:55