- 根据level显示哪张图片
- 在工程文件的res/drawable/新建level-list
如下
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 0-10 显示这张 -->
<item android:drawable="@drawable/wifi1"
android:maxLevel = "10"
></item>
<!-- 20-30 之间显示 -->
<item android:drawable="@drawable/wifi2"
android:maxLevel = "20"
></item>
<item android:drawable="@drawable/wifi3"
android:maxLevel = "30"
></item>
<item android:drawable="@drawable/wifi4"
android:maxLevel = "40"
></item>
</level-list>
package com.qf.day18_uiresources_demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class LevelActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
iv = (ImageView) findViewById(R.id.imageView1);
}
public void clickButton(View v) {
switch (v.getId()) {
case R.id.button1:
iv.setImageLevel(10);
break;
case R.id.button2:
iv.setImageLevel(20);
break;
case R.id.button3:
iv.setImageLevel(30);
break;
case R.id.button4:
iv.setImageLevel(40);
break;
}
}
}