缩放ImageButton以适应各种屏幕尺寸

时间:2016-03-16 18:11:33

标签: java android scale dpi

缩放图像后,我使用带有Nine-patch Generator的ImageButton来检索所有dpi文件以及维护适当的" .9"扩展,并引用按钮的src中的位图,我仍然使用Nexus 5虚拟仿真器(1080X1920,xxhdpi)获得以下结果:

enter image description here

......在这里,ImageButtons不是227X53像素(xxhdpi)......但是,相反,系统会像mdpi一样检索较低的dpi。

这里只是其中一个按钮的XML代码:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/demosBtn"
    android:src="@drawable/demo_btn"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:background="@android:color/transparent" />

至于演示按钮的可绘制资源文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/pressed_demo" android:state_pressed="true"/>
    <item android:drawable="@drawable/norm_demo"/>
</selector>

P.S。我也尝试使用ImageView,将其设置为可点击,将adjustViewBounds设置为true,并将scaleType设置为centerCrop,但它没有工作。

1 个答案:

答案 0 :(得分:1)

使用SVG(可缩放矢量图形)!您可以将它们缩放到任何分辨率,它们仍然看起来超高清。 :d