Sebastian Nowak
Sebastian Nowak

Reputation: 5717

Android scale view

I need to scale View by setting the scale factor in percents. I need to set exactly the same param as ScaleAnimation use, because I'm going to scale it using ScaleAnimation in the future. How do I do it?

Thanks

Upvotes: 1

Views: 3363

Answers (2)

ahodder
ahodder

Reputation: 11439

This will allow you to use straight up float values (percent) when handeling drawing and placements. Refer to: this lovely site which really helps with views.

public class MyView extends View {


    ...


    @Override public void onDraw(Canvas canvas) {
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale((getWidth() > getHeight()) ? getHeight() : getWidth());

        // Your other code

        canvas.restore();
    }

    ...

}

Upvotes: 0

Sebastian Nowak
Sebastian Nowak

Reputation: 5717

I've solved the problem by creating animation xml file with duration=0, which sets desired parameters. It is also possible to create such animation via code. Then to apply it, just use:

Animation animationInit = AnimationUtils.loadAnimation(context, R.anim.gallery_init);
v.startAnimation(animationInit);

Upvotes: 1

Related Questions