当前位置:操作系统 > 安卓/Android >>

Level List

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[html] view plaincopyprint?<?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> 

<?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:

[html]
<?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> 

<?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:
[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) ; 
            } 
        }) ; 
    } 

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) ;
   }
  }) ;
 }
}


效果:
点击前:

 \
 


点击后:

 \
 

 

 

 

 

 

 


 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,