Different images in the same imageview in Android based on status

Source: Internet
Author: User

So so:

if (condition 1) {       image.setbackground (r.id.xxx1);   Else if (condition 2) {       image.setbackground (r.id.xxx2);  

As a matter of fact. If you have more states, you should create a new XML under the Drawable folder:

<level-listxmlns:android= "Http://schemas.android.com/apk/res/android">      <ItemAndroid:maxlevel= "4"android:drawable= "@drawable/stat_sys_battery_0" />      <ItemAndroid:maxlevel= "+"android:drawable= "@drawable/stat_sys_battery_10" />      <ItemAndroid:maxlevel= "$"android:drawable= "@drawable/stat_sys_battery_20" />      <ItemAndroid:maxlevel= "$"android:drawable= "@drawable/stat_sys_battery_40" />      <ItemAndroid:maxlevel= " the"android:drawable= "@drawable/stat_sys_battery_60" />      <ItemAndroid:maxlevel= "The "android:drawable= "@drawable/stat_sys_battery_80" />      <ItemAndroid:maxlevel= "+"android:drawable= "@drawable/stat_sys_battery_100" /> </level-list> 

When you transform a picture in a program, you only need to use:

Imageview.getdrawable (). SetLevel (50);

Android automatically selects the corresponding image based on the level value. The phone shows the remaining charge is the way to display different pictures.

Different images in the same imageview in Android based on status

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.