android UIImageview
来源:互联网 发布:mac ai 毛笔字体 编辑:程序博客网 时间:2024/06/05 18:19
在xml中@drawable/文件名
在代码中R.drawable.文件名
Drawable就是一个可画的对象,其可能是一个可画的对象,也可以是一个图形(shapedrawable),其中访问这些图形类似于操作“内存画布”。
2. 使用方法
2. Bitmap和BitmapFactory
Static Bitmap
decodeByteArray(byte[] data, int offset, int length):从指定字节数组的offset位置开始,讲长度为length的数据解析,创建Bitmap对象
Static Bitmap
decodeFile(string pathname):指定文件中解析、创建Bitmap对象
Static Bitmap
decodeFileDescriptor(FileDescriptor fd):用于从FileDescriptor对应的文件中解析,创建Bitmap对象
Static Bitmap
decodeResource(Resource res, int id):用于根据给定的资源ID从指定资源中解析、创建Bitmap对象
Static Bitmap
decodeStream(InputStream is):从指定输出流中解析、创建Bitmap对象
- public class BitmapTest extends Activity {
- /** Called when the activity is first created. */
- String[] images = null;
- AssetManager assets = null;
- int currentImg = 0;
- ImageView image;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- image = (ImageView)findViewById(R.id.image);
- try
- {
- assets = getAssets();
- //获取/assets/目录下所有文件
- images = assets.list("");
- }
- catch(IOException e)
- {
- e.printStackTrace();
- }
- //获取bn按钮
- final Button next = (Button)findViewById(R.id.next);
- //为bn按钮绑定事件监听器,该监听器将会查看下一张图片
- next.setOnClickListener(new OnClickListener(){
- public void onClick(View sources)
- {
- //如果发生数组越界
- 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 = assets.open(images[currentImg++]);
- }
- catch(IOException e)
- {
- e.printStackTrace();
- }
- BitmapDrawable bitmapDrawable = (BitmapDrawable)image.getDrawable();
- //如果图片还未回收,先强制回收该图片
- if(bitmapDrawable!=null &&
- !bitmapDrawable.getBitmap().isRecycled())
- {
- bitmapDrawable.getBitmap().recycle();
- }
- //改变ImageView显示的图片
- image.setImageBitmap(BitmapFactory.decodeStream(assetFile));
- }
- });
- }
- }
- android UIImageview
- UIImageView------Android中的imageview
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- UIImageView
- css中px和em的区别
- xabbix安装配置
- Merit技术人员价值管理系统——完善编辑结构
- u插件开发,图解每个js之前的通信
- JAVA--List的应用
- android UIImageview
- 开发个人总结
- 如何确定栈的增长方向地址是递增还是递减
- 回到顶部和回到底部动画
- UML之用例图
- 读书笔记| (二)ARM9 嵌入式学习:代码 & 原理篇
- 基于dos的多任务系统实现
- 汇编学习3
- 整数因子分解