android访问asset目录下的资源
android提供了AssetManager来访问asset目录下的资源,
在activity中通过getAssets()获取AssetManager
常用的api如下:
1、列举路径下的资源String[] list(String path)
2、InputStream open(asset目录下的资源路径)
下面是放问asset目录下的图片的代码
package com.example.qunzheng.customerview; import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView; import java.io.IOException;
import java.io.InputStream; public class VisitAssetsResourceActivity extends Activity { private ImageView imageView;
private String[] images = null;
private AssetManager assetManager; private int curImageIndex = 0; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_visit_assets_resource); imageView = (ImageView) findViewById(R.id.image);
assetManager = getAssets();
try {
images = assetManager.list("");
} catch (IOException e) {
e.printStackTrace();
}
} public void viewImage(View view) {
if (curImageIndex >= images.length) {
curImageIndex = 0;
}
/**
* 如果图片资源还没有释放,则释放该资源,防止内存溢出
*/
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
if (drawable != null && drawable.getBitmap() != null && !drawable.getBitmap().isRecycled()) {
drawable.getBitmap().recycle();
} try {
InputStream assertFile = assetManager.open(images[curImageIndex++]);
imageView.setImageBitmap(BitmapFactory.decodeStream(assertFile));
} catch (IOException e) {
e.printStackTrace();
} } }
android访问asset目录下的资源的更多相关文章
- Android 如何引用com.android.internal.R目录下的资源
Android 如何引用com.android.internal.R目录下的资源 项目需求 有一个资源跟系统上的一个资源相同,想要引用它:frameworks/base/core/res/res/dr ...
- Android读取assets目录下的资源
1.获取资源的输入流 资源文件 sample.txt 位于 $PROJECT_HOME/assets/ 目录下,可以在 Activity 中通过 Context.getAssets().open(“s ...
- Android之asset目录下文件的使用
1. 获取AssetManager AssetManager am = context.getAssets(); 2. 列出assets目录下所有文件 String[] filePathList = ...
- 安卓获取Assets目录下的资源
获取Assets目录下的资源 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 ! ...
- centos7限制普通用户访问单一目录下的单一文件
要求给开发同事开设一个查看日志的账号,并限制其只能访问该目录下的单一文件 1.先新建账号 useradd loglook passwd loglook 家目录为/home/loglook 2.日志的属 ...
- Spring中无法访问resources目录下页面或静态资源
1.新建项目,在 resources 目录下创建 views 目录,在 views 目录下创建 index.html 页面,项目跑起来,浏览器访问页面,提示找不到页面之类的错误提示. 2.再尝试访问图 ...
- SprignBoot是如何访问工程目录下的静态资源?
目录 1.牛刀小试 1.1 图片静态资源的访问 1.2 为静态资源添加访问前缀 1.3 WelCome Page 的奇妙跳转 2.那么,SpringBoot是如何做到的呢? 1. ...
- Asp.Net配置不允许通过url方式访问目录下的资源
Asp.Net网站发布后,有部分文件为了安全性,是不能直接通过url访问获取 通常有2种做法: 1.将文件目录建立在 App_code 或者App_Data 等默认的隐藏目录下 2.将文件的目录添加到 ...
- Android复制assets目录下的图片到内存
转自:http://www.chenwg.com/android/android%E5%A4%8D%E5%88%B6assets%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84 ...
随机推荐
- 【无聊放个模板系列】HDU 1269 (SCC)
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- java区分大小写,使用TAB进行缩进,public类名只能有一个,而且文件名与类名保持一致.
java的类必须大写 java区分大小写,使用TAB进行缩进,public类名只能有一个,而且文件名与类名保持一致. 在dos用上下箭头,调用已用过的命令
- easyui源码翻译1.32--Menu(菜单)
前言 使用$.fn.menu.defaults重写默认值对象.下载该插件翻译源码 菜单组件通常用于快捷菜单.他是构建其他菜单组件的必备基础组件.比如:menubutton和splitbutton.它还 ...
- Linux内核学习笔记: uid之ruid,euid,suid
转自: http://www.linuxidc.com/Linux/2011-09/43194.htm 看UNIX相关的书时经常能遇到这几个概念,但一直没有好好去理清这几个概念,以致对这几个概念一直一 ...
- 使用 jQuery.i18n.properties 实现 Web 前端的国际化
jQuery.i18n.properties 简介 在介绍 jQuery.i18n.properties 之前,我们先来看一下什么是国际化.国际化英文单词为:Internationalization, ...
- ruby oop学习
class Man def initialize(name,age) @name=name @age=age end def sayName puts @name end def sayAge put ...
- Oracle系列之函数
涉及到表的处理请参看原表结构与数据 Oracle建表插数据等等 如何调用该过程 call function_name(参数值1,参数值2); 创建function来查询某个雇员的工资 create ...
- nginx-rrd监控nginx访问数
一 .查看已安装的nginx是否包含stub_status模块 /usr/local/nginx/sbin/nginx -V nginx version: Nginx/1.2.0 configure ...
- 清理Xcode中无用的 Provisioning Profile.
Xcode中如果添加过多个开发者账号, 慢慢就会发现 Provisioning Profile 有很多, 无用的 Provisioning Profile Xcode也不会自动删除, 想要清理的话, ...
- 【转】iTunes下载速度太慢?两招帮你提速!-- 不错
原文网址:http://bbs.app111.com/thread-275-1-1.html 不用说,很多朋友都发现在大陆,下载 iTunes 上的东西实在是慢如蜗牛,小一点的软件还能坚持一下,大一点 ...