Android的MDPI可绘为Droid手机和Xoom的使用上? [英] Android mdpi drawables for use on both Droid phone and Xoom?

查看:97
本文介绍了Android的MDPI可绘为Droid手机和Xoom的使用上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Droid的(电话)开发的应用程序。在应用中,我使用的:

I have an app developed for a Droid (phone). In the app, I use:

位图B = BitmapFactory.de codeResource(getResources(),R.drawable.bg);

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.bg);

要设置应用程序的背景位图。位图的尺寸为480x800
这是对Droid的WVGA屏幕尺寸(无状态或标题栏)。

To set the background bitmap in the application. The bitmap is sized 480x800 which is the WVGA screen size of the Droid (without status or title bar).

两个问题:
当我旋转手机Droid进入横向模式和背景不再适合正确。我该如何告诉应用程序需要的时候我不使用布局使用风景模式?

Two questions: When I rotate the phone, the Droid goes into landscape mode and the background no longer fits correctly. How do I tell the App it needs to use landscape mode when I'm not using a layout?

二,当我对Xoom的运行这个程序,它采于mdpi绘制这是无处Xoom的屏幕大小接近。我如何定义一个拥有1280×800尺寸的第二MDPI绘制?我想,如果我用的布局,我会创造一个布局XLARGE目录并放置一个1280x800的背景在布局ImageView的,正确的?

Second, when I run this app on the Xoom, it picks the mdpi drawable which is nowhere near the size of the Xoom screen. How do I define a second mdpi drawable that has a 1280x800 size? I think if I were using layouts, I would create a layout-xlarge directory and place a 1280x800 background in the imageview of that layout, correct?

谢谢!

更新的 * 的:
感谢伟大的答案!我upvoted大家。
我更新了code使用绘-XLARGE端口/绘-XLARGE土地为Xoom的和可绘制端口-MDPI /绘-土地MDPI的Droid的。

Update *: Thanks for the great answers! I upvoted everyone. I updated the code to use drawable-xlarge-port/drawable-xlarge-land for the Xoom and drawable-port-mdpi/drawable-land-mdpi for the Droid.

我需要直接画到画布上的活动和不知道如何从那里我为了做动画延伸查看并挂到的onDraw()类中使用的setContentView()我不使用布局(会需要一个单独的张贴)。

I'm not using layouts as I needed to draw directly onto the activity canvas and not sure how to use setContentView() from within the class where I extend View and hook into onDraw() in order to do the animation (would need to be a separate posting).

如果我能弄清楚如何将图像旋转自己,我确实可以用绘制废除 - * - 土地和* -port目录。

If I can figure out how to rotate the image myself I could indeed do away with the drawable-*-land and *-port directories.

推荐答案

您可以针对绘图资源,而不仅仅是布局。你想绘制-HDPI-大长土地对于第一种情况下(假设你让系统手柄转动的活动,并重新创建您的活动)和绘制-MDPI-XLARGE 第二。

You can target drawables, not just layouts. You want drawable-hdpi-large-long-land for the first situation (assuming you're letting the system handle rotation events and recreate your activity), and drawable-mdpi-xlarge for the second.

当然,这是徒劳的尝试与每一个可以想象的手机分辨率单独的图像出货;部分原因是因为有很多你需要的,部分原因是因为有些目标不是微(854x480的的800×480和手机在那里都HDPI-大长,例如,尽管54px差)。尝试使用可扩展的图像,可拉伸9patch或图像可以只固定在右上角(你可以定义使用XML定义bitmapdrawable拉伸行为)。

Of course it's futile to try to ship with a separate image for every conceivable phone resolution; partially because there's a lot you'd need, and partially because some targets aren't differentiable (the 854x480 and 800x480 phones out there are all hdpi-large-long, for example, despite the 54px difference). Try to use a scaleable image, a stretchable 9patch, or an image you can just fix at the top-right corner (you can define stretch behaviors using an XML-defined bitmapdrawable).

这篇关于Android的MDPI可绘为Droid手机和Xoom的使用上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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