你可以使用以下代码为drawable中的图片设置宽高:

// 获取drawable资源
Drawable drawable = getResources().getDrawable(R.drawable.your_drawable);

// 设置宽高
int width = 100; // 宽度
int height = 100; // 高度
drawable.setBounds(0, 0, width, height);

通过 getResources().getDrawable(R.drawable.your_drawable) 方法获取 drawable 资源,然后使用 setBounds() 方法设置宽高。setBounds() 方法接受四个参数:左边距、上边距、右边距、下边距。在这里我们将左边距和上边距都设置为 0,右边距和下边距设置为宽度和高度。

安卓开发 我想在代码中为drawable中的图片设置宽高

原文地址: http://www.cveoy.top/t/topic/bYUq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录