Android的Bitmap和BitmapDrawable类解析-android学习之旅(六十)
使用简单图片
使用Drawable对象
bitmap和BitmapDrawable对象
package peng.liu.test;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ClipDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends Activity{
String[] images;
ImageView image;
int currentImg;
AssetManager asset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.imageBit);
try{
asset = getAssets();
images = asset.list("");
}catch (Exception e){
e.printStackTrace();
}
findViewById(R.id.btnBit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (currentImg >= images.length){
currentImg = 0;
}
while (!images[currentImg].endsWith(".png")&&!images[currentImg].endsWith(".jpg")&&!images[currentImg].endsWith(".gif")){
currentImg++;
if (currentImg >= images.length){
currentImg = 0;
}
InputStream assetFile = null;
try{
assetFile = asset.open(images[currentImg++]);
}catch (Exception e){
e.printStackTrace();
}
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
if (drawable != null && !drawable.getBitmap().isRecycled()){
drawable.getBitmap().recycle();
}
image.setImageBitmap(BitmapFactory.decodeStream(assetFile));
}
}
});
}
}
Android的Bitmap和BitmapDrawable类解析-android学习之旅(六十)的更多相关文章
- Android广播接收器Broadcast Receiver-android学习之旅(十二)
首先继承BroadcastReceiver类,并在manifest中注册 public class MyReceiver extends BroadcastReceiver { public MyRe ...
- Android的RadioButton和checkBox的用法-android学习之旅(十九)
RadioButton和checkBox简介 单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:che ...
- android布局Relative和gridLayout-android学习之旅(十六)
Relative布局简介 相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局. 属性设置介绍 RelativeLayout.Layoutparam中只能设置为true和false的属 ...
- android布局##TableLayout和FrameLayout-android学习之旅(十五)
TableLayout 表格布局 tablelayout简介 表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器.表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列, ...
- 【转】 Pro Android学习笔记(六十):Preferences(4):MultiSelect List Preference
目录(?)[-] XML文件 在设备中保存 读出信息 ListPreference提供单选列表,我们可以通过CheckBoxPreference提供多选列表.此外,Android在3.0后提供Mult ...
- Android使用局和数据实现天气项目-android学习之旅(十二)
1.首先注册聚合数据账号,下载相应的sdk 2.导入jar包和 so文件 配置Application,初始化sdk <application //自己新建的application类 androi ...
- Android四大组件之一Service介绍-android学习之旅(十二)
基本概念: service是android四大组件之一,运行在后台执行耗时操作,并不提供用户界面.其他组件如acticity可以通过startService启动该组件,也可以通过bindService ...
- Android的ViewAnimator而它的子类ViewSwitcher-android学习之旅(三十三)
ViewAnimator遗传FrameLayout,重合使用多个组件.可以增加部件数量,然后会有时间切换动画. ViewAnimator及其子类的继承关系 ViewAnimator经常使用属性 Vie ...
- Android 9Patch图片的使用-android学习之旅(十八)
9patch的使用方法 9patch图片常被用来做消息发送等的图片,只是缩放照片的部分区域,使得图片的整体形状不会受到影响,比较方便. 下面我们介绍一下: 在android的SDK安装目录下的tool ...
随机推荐
- 使用Canvas实现动画效果 | DKlogs -- 设计 | 生活
使用Canvas实现动画效果 | DKlogs -- 设计 | 生活 使用Canvas实现动画效果
- ios sourecTree
1, http://www.jianshu.com/p/be9f0484af9d 2, http://blog.csdn.net/viewcode/article/details/42291973
- poj 3411 Paid Roads(dfs)
Description A network of m roads connects N cities (numbered to N). There may be more than one road ...
- Unity 编辑器扩展自定义窗体
这次看见Unity还可以自定义弹出窗体,让我很好奇.于是就去网上找文章看了看. 如果想自定义窗体需要把类放入Editor文件夹下面. 代码如下: using UnityEngine; using Un ...
- 使用 React和webpack开发和打包发布
建议在 React 中使用 CommonJS 模块系统,比如 browserify 或 webpack,本次使用 webpack. 第一步.安装全局包 $ npm install babel -g $ ...
- Web安全技术(3)-浏览器的跨域访问
http://www.blogjava.net/linli/archive/2015/04/22/424584.html 一.浏览器介绍 对于Web应用来说,浏览器是最重要的客户端. 目前浏览器五花八 ...
- php常用的操作
一. php配置 1.禁止一些函数disable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passt ...
- JavaScript关闭浏览器
(*^__^*) 嘻嘻……,以前我找关闭浏览器选项卡的代码找不到,我还以为要用后台代码关呢?今天发现只要简单2句JavaScipt代码就可以了.看来很多东西还是在于平时的积累啊的说! 模仿延儿的口气了 ...
- C# winform平台下使用spread控件导出excel表格
//首先要引入两个控件:1.根据自己的office 版本在项目->添加引用->microsoft office object 12.0 library (2010版) //2.在.net中 ...
- js继承 prototype和constructor
function a(){ this.name="aaa"; } function b(){ ...