代码改变世界

Level List

2013-04-24 14:02  java20130722  阅读(196)  评论(0编辑  收藏  举报

Level List

用户管理图片需要相互切换显示。

文件存放位置:
res/drawable/

语法:
<?xml version="1.0" encoding="utf-8"?>
<level-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/drawable_resource"
        android:maxLevel="integer"
        android:minLevel="integer" />
</level-list>

用法:

level_list_button_checkable.xml
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/checkbox"
        android:maxLevel="0" />
    <item
        android:drawable="@drawable/checkbox_selected"
        android:maxLevel="1" />
</level-list>
layout_level_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/level_list_button_checkable"
        android:text="Button" />

</RelativeLayout>
LevelListActivity.java:
package com.hualu.animation.levellist;

import com.hualu.animation.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LevelListActivity extends Activity {

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_level_list) ;
		final	Button b = (Button)this.findViewById(R.id.button1) ;
		b.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				System.out.println("level change"+b.getBackground().getLevel());
				
				b.getBackground().setLevel(1) ;
			}
		}) ;
	}
}

效果:
点击前:


点击后: