同一个ImageView显示不同的图片(LevelDrawable)
2015-12-05 12:54
295 查看
if (条件1)
{
image.setBackground(R.id.xxx1);
}
else if (条件2)
{
image.setBackground(R.id.xxx2);
}
else if …
其实我们可以使用另一个简便的方法实现相同的功能
首先,在res/drawable下建立一个xml文件,内容如下
?
程序中变换图片时,只需要使用
imageview.getDrawable().setLevel(1);
或者imageview.setImageLevel(1);
…
Android会根据level的值自动选择对应的图片。手机显示剩余电量就是用这个方法来显示不同图片的
使用LevelDrawable注意几点:
1、默认的level为0,如果没有和0匹配的level,那么就不显示。
2、level匹配以maxLevel优先。即如果有个item,min:1,max:2。 另一份item,min:2,max:3。
如果此时设置level=2,那么会匹配第一个item。
相关文章推荐
- linux下安装mongodb
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 公式推导
- 数据库原理 知识点总结
- poj 3352 Road Construction 双连通图
- 多态图标(3)-HTML使用CSS切换
- Android统计图表MPAndroidChart:动态添加数据更新【6】
- Could not create the view An unexpected exception was thrown.问题解决
- Module-Zero之启动模板
- ubuntu matplotlib的安装
- LintCode-剑指Offer-(54)转换字符串到整数
- 输入一位数组后得到其最小值
- java环境配置
- 批处理安装nodejs
- gets scanf以及缓冲区域的问题
- Android开发日记(三)
- cygwin 安装apt-cyg命令
- Stream closed
- xcode操作备忘
- [LeetCode]Symmetric Tree
- 看我linux(ubuntu)下的64位编译器编译32位程序