Android scale view

泄露秘密 提交于 2019-12-08 03:25:57

问题


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


回答1:


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



回答2:


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

    ...

}


来源:https://stackoverflow.com/questions/7191965/android-scale-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!