使用Android上的图像精灵 [英] Using image sprites on android

查看:403
本文介绍了使用Android上的图像精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形象(588x449)精灵与不同队徽的集合。在Android中我有相应的ImageView的显示这样的:

I have an image (588x449) sprite with a collection of different team logos. In Android I have the corresponding ImageView displaying this:

        <ImageView android:id="@+id/image_team_logo" 
            android:src="@drawable/teamheaderssprite" 
            android:layout_height="25dp" 
            android:layout_marginLeft="5dp" 
            android:layout_marginTop="10dp" 
            android:layout_width="296dp" android:scaleType="matrix"/>   

以上将正确地显示在左上角的一块我的形象的。我的问题是我希望能够移动显示这样我就可以跳转到精灵其他区域在图像中的位置。这是,我只是没有看到Android的XML格式的'位置'type属性在HTML / CSS pretty的通行做法。

The above will correctly display the piece of my image in the upper left hand corner. My issue is I want to be able to move the position in the image being displayed so I can jump to another area in the sprite. This is pretty common practice in html/css, I am just not seeing a 'position' type property in android xml.

推荐答案

在Android上不能使用精灵以同样的方式,你可以使用HTML。有一个办法,我能想到的,虽然模拟精灵:莱精灵出全部水平(或垂直),然后用<一个href="http://developer.android.com/guide/topics/resources/drawable-resource.html#Clip">ClipDrawable确定每个级别的精灵的一个新的组成部分。然后定义每个View适当的水平。 (如果在精灵的图像不一样的大小,您可能需要使用InsetDrawable为好。)

You can't use sprites in the same way on Android you can with HTML. There is one way I can think of to simulate sprites though: Lay the sprite out entirely horizontally (or vertically), then use a ClipDrawable to define each level as a new part of the sprite. Then define the level of each View as appropriate. (If the images in the sprite aren't all the same size, you may need to use InsetDrawable as well.)

但是,我会认真反思在Android中使用精灵。有原因的网页使用的精灵,这不是因为它们更容易 - 这是因为它加快了网页,因为你不必须使多个HTTP请求的。由于该图像将已经在你的发行版APK,你不spriting他们获得什么。

However, I would seriously rethink using sprites in Android. There are reasons why web pages use sprites, and it's not because they're easier - it's because it speeds up webpages because you don't have to make multiple HTTP requests. Since the images will already be in your release APK, you don't gain anything by spriting them.

不仅如此,但你做一些伤害由spriting在Android上:

Not only that, but you're doing some harm by spriting on Android:

  1. 内存在一些Android手机的约束是远远低于你所期望的。如果图形的全部都在存储器在任何给定时间,即降低了存储器必须为所有的量其他

  1. Memory constraints on some Android phones are much lower than you might expect. If the entirety of your graphics are in memory at any given time, that lowers the amount of memory you have for everything else.

精灵将很难处理,一旦你开始写不同的屏幕密度(LDPI,MDPI,华电国际)。

Sprites will be harder to handle once you start writing for different screen densities (ldpi, mdpi, hdpi).

这篇关于使用Android上的图像精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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