我的应用程序中有一些图像,并希望对多个屏幕使用相同的参考,是否可以使用xml中的缩放标记来重新调整图像大小并使用不同的分辨率?当我尝试它时,图片消失了!
例如我这样做了:
首先,我创建了新的XML文件add_more_items_scaled
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/add_more_items"
android:scaleWidth="75%"
android:scaleHeight="75%">
</scale>
然后创建了另一个XML文件add_more_items_button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true"></item>
<item android:drawable="@drawable/add_more_items_scaled"
android:state_focused="true"></item>
<item android:drawable="@drawable/add_more_items_scaled"></item>
当我设置按钮的背景@android:background:“@ drawable / add_more_items_button”它给了我一个空按钮
那么,有什么建议吗?
答案 0 :(得分:0)
您无法将缩放标记应用于图像,因为它的目的是缩放可绘制而非缩放图像。
正如documentation所说:
A drawable defined in XML that changes the size of another drawable based on its current level.
<强>溶液强>
您可以在按钮上加权,而不是使用Button
,您可以使用ImageButton
并将scaleType
设置为fitXY
以填充它的范围。< / p>