LevelListDrawable的使用
2016-12-08 14:48
429 查看
LevelListDrawable对应level-list 标签 表示一个Drawable集合,每个drawable都有一个level,在代码中可以根据不同等级切换不同的drawable
MainActivity.java
<?xml version="1.0" encoding="utf-8"?> <level-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/picture" android:minLevel="1" android:maxLevel="10"/> <item android:drawable="@mipmap/img" android:minLevel="11" android:maxLevel="20"/> </level-list>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/imge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="50dp" android:src="@drawable/level_list_drawable"/> <Button android:id="@+id/bt_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:text="下一张"/> </LinearLayout>
MainActivity.java
package com.zhoujian.drawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { private int mLevel; private ImageView imge; private Button mButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imge = (ImageView) findViewById(R.id.imge); imge.setImageLevel(10); mButton = (Button) findViewById(R.id.bt_button); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mLevel= imge.getDrawable().getLevel(); if (mLevel==10) { imge.setImageLevel(20); } else { imge.setImageLevel(10); } } }); } }
相关文章推荐
- Drawable基础知识总结----drawable标签LevelList、inset、scale、clip的使用
- android levellistdrawable 基本使用
- LevelListDrawable的简单使用
- Drawable Animation -- 使用多幅图片实现动画
- 下载大量图片内存溢出的解决方案(使用SoftReference<Drawable>)
- 转:notification更新数字的显示及AnimationDrawable的结合使用
- Drawable、Bitmap、Canvas和Paint的关系以及部分使用方法
- 使用GDK_WINDOW_XID时提示drawable is not a pixmap or window
- Drawable、Bitmap、Canvas和Paint的关系以及部分使用方法
- 【转】Android UI美化之Shape Drawable的使用
- Android 背景颜色处理[使用 Drawable.setColorFilter(),或者paint.setColorFilter()]
- 使用Drawable中默认的12种颜色,得到屏幕的大小,样式
- notification更新数字的显示及AnimationDrawable的结合使用
- Drawable、Bitmap、Canvas和Paint的关系以及部分使用方法
- ListView中混合使用Drawable文件夹资源和网络资源
- 使用TransitionDrawable实现两张图片的过渡效果
- android NinePatchDrawable 9.png图片使用制作
- Drawable、Bitmap、Canvas和Paint的关系以及部分使用方法
- Android学习15--使用(Drawable)资源
- Android中Shape Drawable在xml中的使用