使用简单图片

使用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学习之旅(六十)的更多相关文章

  1. Android广播接收器Broadcast Receiver-android学习之旅(十二)

    首先继承BroadcastReceiver类,并在manifest中注册 public class MyReceiver extends BroadcastReceiver { public MyRe ...

  2. Android的RadioButton和checkBox的用法-android学习之旅(十九)

    RadioButton和checkBox简介 单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:che ...

  3. android布局Relative和gridLayout-android学习之旅(十六)

    Relative布局简介 相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局. 属性设置介绍 RelativeLayout.Layoutparam中只能设置为true和false的属 ...

  4. android布局##TableLayout和FrameLayout-android学习之旅(十五)

    TableLayout 表格布局 tablelayout简介 表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器.表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列, ...

  5. 【转】 Pro Android学习笔记(六十):Preferences(4):MultiSelect List Preference

    目录(?)[-] XML文件 在设备中保存 读出信息 ListPreference提供单选列表,我们可以通过CheckBoxPreference提供多选列表.此外,Android在3.0后提供Mult ...

  6. Android使用局和数据实现天气项目-android学习之旅(十二)

    1.首先注册聚合数据账号,下载相应的sdk 2.导入jar包和 so文件 配置Application,初始化sdk <application //自己新建的application类 androi ...

  7. Android四大组件之一Service介绍-android学习之旅(十二)

    基本概念: service是android四大组件之一,运行在后台执行耗时操作,并不提供用户界面.其他组件如acticity可以通过startService启动该组件,也可以通过bindService ...

  8. Android的ViewAnimator而它的子类ViewSwitcher-android学习之旅(三十三)

    ViewAnimator遗传FrameLayout,重合使用多个组件.可以增加部件数量,然后会有时间切换动画. ViewAnimator及其子类的继承关系 ViewAnimator经常使用属性 Vie ...

  9. Android 9Patch图片的使用-android学习之旅(十八)

    9patch的使用方法 9patch图片常被用来做消息发送等的图片,只是缩放照片的部分区域,使得图片的整体形状不会受到影响,比较方便. 下面我们介绍一下: 在android的SDK安装目录下的tool ...

随机推荐

  1. LeeCode-Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has For exampl ...

  2. [Ext JS 4] 实战之多选下拉单 (带checkbox)

    前言 Ext js 创建一个多选下拉单的方式很简单, 使用Ext.form.ComboBox, 设置 multiSelect 为true 就可以了. 但是如果要在每个下拉之前加上一个checkbox, ...

  3. 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago

    # #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...

  4. No module named MYSQLdb 问题解决

    问题描述: 报错:ImportError: No module named MySQLdb 对于不同的系统和程序有如下的解决方法: easy_install mysql-python (mix os) ...

  5. 使用Comparable接口的小例子

    代码: public class Student implements Comparable<Student> { private int id; private String name; ...

  6. Keepalived+Lvs+Mysql主主复制

    一简单介绍 Keepalived+lvs+mysql主主复制是比較经常使用的一种Mysql高可用方案,当中lvs 提供读负载均衡,Keepalived通过虚拟vip漂移实现故障自己主动转移,而Mysq ...

  7. java基础之集合List-ArrayList、LinkedList、Vector的差别

    PS:本篇博客主要參考jdk的底层源代码.而非自己动手写代码. 请问ArrayList.LinkedList.Vector的差别 ①ArrayList底层实际上是採用数组实现的(而且该数组的类型的Ob ...

  8. Swift中NSData与NSDictionary之间的相互转换

    原创Blog,转载请注明出处 使用NSKeyedUnarchiver类来进行相互转换 1.NSDictionary转NSData var dictionaryExample : [String:Any ...

  9. 使用一个HttpModule拦截Http请求,来检测页面刷新(F5或正常的请求)

    在Web Application中,有个问题就是:“我怎么来判断一个http请求到底是通过按F5刷新的请求还是正常的提交请求?” 相信了解ASP.NET的人知道我在说什么,会有同感,而且这其实不是一个 ...

  10. Java编程的23种设计模式

    设计模式(Design Patterns)                                   --可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用. ...