Android的:如何绘制与设备无关的同样大小的ImageView的? [英] Android: how to draw an ImageView with the same size regardless of device?

查看:119
本文介绍了Android的:如何绘制与设备无关的同样大小的ImageView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个工具栏上的我的应用程序。工具栏将使用ImageViews为应用程序按钮。我想ImageViews是完全一样的大小,而不管设备;通过相同大小我的意思是,当渲染到屏幕上,如果我用尺子测量它们的尺寸将是相同的。我想这个大小为〜10毫米(我的食指的宽度)。

I want to put a toolbar in my application. The toolbar will use ImageViews as application buttons. I would like the ImageViews to be the exact same size regardless device; by "same size" I mean that, when rendered to the screen, if I measure them with a ruler, the dimensions will be the same. I would like this size to be ~10mm (the width of my index finger).

我已经完全成功在完成这一点。

I have been completely unsuccessful in accomplishing this.

我测试在一个MDPI,大屏宏碁Iconia Tab键和华电国际中等屏幕的三星Galaxy Tab。如果我设置 layout_width =50dip layout_height =50dip,按钮呈现为〜10毫米对三星和〜对宏碁8毫米。如果我设置的按钮为 layout_width =12毫米 layout_height =12毫米,它们渲染为12毫米上在银河宏碁〜9毫米(即混淆呈现50dip就越大银河比宏碁​​,但12毫米呈现在Galaxy比宏碁更小)。

I am testing on a MDPI, large screen Acer Iconia Tab and a HDPI medium screen Samsung Galaxy Tab. If I set layout_width="50dip" and layout_height="50dip", the buttons render as ~10mm on the Samsung, and ~8mm on the Acer. If I set the buttons as layout_width="12mm" and layout_height="12mm", they render as 12mm on the Acer and ~9mm on the Galaxy (confusing that 50dip renders bigger on the Galaxy than the Acer, but 12 mm renders smaller on the Galaxy than on the Acer).

如果我把我的绘制,于mdpi文件夹32pix点¯x32pix图标(和绘制,华电国际文件夹中没有等价物),并设置 layout_width =WRAP_CONTENT layout_height =WRAP_CONTENT;结果是相似的,如果设置为50dip,三星是10mm左右,宏碁约为8mm。如果我添加一个48pix点¯x48pix我绘制,华电国际文件夹图标,没有变化; presumably因为宏碁仍然使用于mdpi图标,三星采用了更大的一个,但因为它知道它的华电国际(如果有信心,这令人吃惊的比例出现了50%秤了,因为如果我移动48pix图标MDPI文件夹中,并没有什么在华电国际文件夹中的图标显示对三星非常大)。

If I place a 32pix x 32pix icon in my drawable-mdpi folder (and no equivalent in the drawable-hdpi folder), and set layout_width="wrap_content" and layout_height="wrap_content"; the results are similar to if set to 50dip, the Samsung is about 10mm, the Acer about 8mm. If I add a 48pix x 48pix icon to my drawable-hdpi folder, there is no change; presumably because the Acer still uses the mdpi icon and the Samsung uses the bigger one, but scales it down by 50% because it knows its hdpi (if am confident that this surprising scaling occurs because if I move the 48pix icon to the mdpi folder, and have nothing in the hdpi folder, the icon shows very large on the Samsung).

我很迷茫,真的可以使用的建议。如何让我的指尖按键大小,无论dpi和屏幕大小?

I am confused and could really use advice. How do I make my button fingertip sized regardless of dpi and screen size?

推荐答案

好吧,我终于想通了,这是怎么回事:

Ok, I finally figured out what is going on:

问题是一个图像按钮谁的宽度被指定为10毫米,
显示了我的银河标签7mm,平整和关于我的ICONIA TAB9毫米。
有2方面的原因而显著差异:

The problem is that a image button who's width is specified as 10mm, shows as about 7mm on my Galaxy tab, and about 9mm on my Iconia Tab. There are 2 reasons for this rather significant difference:


  1. 的ICONIA TAB报告其xdpi为〜160,当其实际xdpi
    是〜150。

  2. 蜂窝采用了全新绘制它的按钮背景,与
    比升级Froyo的绘制显著收窄。

第1期账户的区别,第2期账户约0.6毫米
为剩余部分。问题2可以通过选择两个中的一个可以解决
背景,与应用程序打包它,并且将其指定为
背景为的ImageButton。问题1解决不了,但一旦问题2处理它创造的差异相对较小
用。

Issue 1 accounts for about .6mm of the difference, Issue 2 accounts for the remainder. Issue 2 can be solved by choosing one of the two backgrounds, packaging it with the application, and specifying it as the background for the ImageButton. Issue 1 cannot be resolved, but the difference it creates is relatively minor once issue 2 is dealt with.

这篇关于Android的:如何绘制与设备无关的同样大小的ImageView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆