Android how to resize (scale) an xml vector icon programmatically

后端 未结 2 680
情书的邮戳
情书的邮戳 2021-02-06 03:42

This is driving me crazy. I would like to be able to resize an xml vector drawable icon programmatically in order to use it in an ImageView.

This is what I\'ve done so f

2条回答
  •  忘了有多久
    2021-02-06 03:49

    You can change the width and height of your imageview programmatically. Since vector drawables will preserve the original quality of the image, this will make the desired output happen.

    ImageView iv = (ImageView) findViewById(R.id.imgview);
    int width = 60;
    int height = 60;
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width,height);
    iv.setLayoutParams(params);
    

提交回复
热议问题