如何获得图像阵列? [英] How to get an array of images?

查看:223
本文介绍了如何获得图像阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个电池应用程序,它应通知电池百分比用户图像的形式。现在电池百分比0-100,我需要101图像中的所有。我想要做的是它可以插入所有这些图像在阵列中,并使用它们相应。例如,如果我的电池百分率为47%,在位置47的图像中阵列应采用该资源。 也就是说,假设我有一个名为电池 ImageView的,我有一个阵列命名batteryimage(包含所有101图像),然后我应该能够做到这一点,

I want to make a Battery app which should notify the battery percentage to user in form of image. Now for battery percentage 0-100, I need 101 images in all. What I want to do is that is it possible to insert all these images in an array and use them accordingly. For instance, if my battery percentage is 47%, the image in array at position 47 should be the resource. That is, suppose I have ImageView named Battery, and I have an array named batteryimage(containing all the 101 images) then I should be able to do this,

Battery.setBackgroundResource(R.drawable.batteryimage[p])

其中 P 将电池的当前百分比,我会用code搞定了。

where p will be the current percentage of battery, which I will get by code.

希望大家明白我想要什么..感谢名单提前..

Hope you all understood what I want.. Thanx in advance..

推荐答案

定义图片ID的数组像这样

define a array of image id like this

int[] p = {R.drawable.image1, R.drawable.image2....}

现在该阵列的不同条件下使用的部件如

now for different condition use member of this array like

Battery.setBackgroundResource(p[0])  // or p[1]

也可以使用ENUM,使其更具可读性。

or you can use ENUM to make it more readable..

但是..我想你应该考虑以另一种方式。而不是使用100种不同的图像创建一个自定义进度,以显示你的电池的不同状态。

But.. I think you should think in another way. instead of using 100 different image create a custom progressbar to show different state of your battery.

要知道的进度条基本看文档这里 并创建自定义的进度,你可以检查此因此质疑

To know the basics of Progress bar see doc here and to create custom progressbar you can check this so question

这篇关于如何获得图像阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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