为各种屏幕尺寸缩放ImageButton

问题描述:

将用于ImageButton的图像与Nine-patch Generator一起使用以检索所有dpi文件以及保持相应的“.9”扩展名,并在src中引用位图按钮的,我仍然得到以下结果与Nexus 5的虚拟仿真器(1080×1920,xxhdpi):为各种屏幕尺寸缩放ImageButton

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> 

附:我也试过这与ImageView以及设置为可点击,将adjustViewBounds设置为true,并将scaleType设置为centerCrop,但它没有工作。

+0

您正在使用真实9位补丁位图的图像?如果是这样,我可以看到这样的错误。突出显示的错误上方的行使我认为他们不是。如果是这样,手动添加扩展将不起作用。你试图达到什么样的最终效果? – wblaschko

+0

好吧,它们最初是缩放PNG图像,然后我将它们上传到相应的dpi res目录中,然后“手动”将dpi文件和目录的名称与扩展名“.9”一起更改为文件的原始名称如果这就是你要求lol – DaveNOTDavid

+0

http://stackoverflow.com/questions/36039936/scaling-imagebuttons-for-various-screen-sizes ...基本上,Nexus 5(xhdpi)模拟器似乎检索dpi文件从lpdi目录改为。 – DaveNOTDavid

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

+0

我欣赏这个建议,但我的问题在于,无论何时我引用ImageButton的src中的位图,系统都会根据屏幕的dpi来选择错误的位图(如上面编辑文章所示)。 – DaveNOTDavid