Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个在 XML 文件中定义的开关,我在其中设置
amdroid:drawableLeft="@drawable/my_image
但是图像太大,溢出屏幕。有没有办法在 XML 中调整可绘制对象的大小,还是需要以编程方式完成?
最好的选择是调整实际图像的大小并拥有一个图标大小的版本。通过消除对图像重新采样的需要,这将提高性能并减少内存使用量。
如果做不到这一点,您可以以编程方式设置可绘制对象:
Drawable icon = getResources().getDrawable(R.drawable.my_image); icon.setBounds(0, 0, width, height); myView.setCompoundDrawables(icon, 0, 0, 0);