Skip to content

Conversation

@farfromrefug
Copy link

I needed scaleType to work with an imageView. That pr does that.
Here is a simple example on how to use it

imageView = new ImageView(context) {
            @Override
            protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                Drawable drawable  = imageView.getDrawable(); 

                if (!(drawable instanceof SVGDrawable)) {
                    return;
                } 
                imageView.setImageDrawable(null); 
                int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
                int vHeight = getHeight() - getPaddingTop() - getPaddingBottom();
                ((SVGDrawable)drawable).adjustToParentSize(vWidth, vHeight);
                imageView.setImageDrawable(drawable);
            }

            @Override
            public void setScaleType (ScaleType scaleType) {
                super.setScaleType(scaleType);
                Drawable drawable  = getDrawable(); 

                if (!(drawable instanceof SVGDrawable)) {
                    return;
                } 
                setImageDrawable(null); 
                ((SVGDrawable)drawable).setScaleType(scaleType);
                int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
                int vHeight = getHeight() - getPaddingTop() - getPaddingBottom();
                ((SVGDrawable)drawable).adjustToParentSize(vWidth, vHeight);
                setImageDrawable(drawable);
            } 

            @Override
            public void setImageDrawable(Drawable drawable) {
                if (!(drawable instanceof SVGDrawable)) {
                    super.setImageDrawable(drawable);
                    return;
                }
                if (getDrawable() == drawable) {
                    return;
                }
                SVGDrawable svg = (SVGDrawable) drawable;
                svg.setScaleType(getScaleType());
                int vWidth = getWidth() - getPaddingLeft() - getPaddingRight();
                int vHeight = getHeight() - getPaddingTop()
                        - getPaddingBottom();
                svg.adjustToParentSize(vWidth, vHeight);
                super.setImageDrawable(svg);
            }
        };

@TrevorPage
Copy link
Owner

Thank you so much for this work :) I promise I'll look at your pull requests as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants