一.创建 

   1./src/main/assets

   2.切换到Project视图模式,在main下新建文件夹assets

二.特点

   1.和res同等级别

   2.主要是存放项目中的大文件

   3.文件不受R类的管理

三.API

   1.AssetManager  资产管理器

      1-getAssets()   得到资产管理器

      2-open(文件名)   返回文件的InputStream

   2.ImageView:setImageBitmap(Bitmap  实例)  设置图片视图的位图

   3.Bitmap   位图:BitmapFactory.decodeFile(图片文件路径)   使用工厂方法得到图片文件的Bitmap.

 

图片内部存储代码展示:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp3.MainActivity"
11     android:orientation="vertical">
12 
13 
14 
15     <Button
16         android:layout_width="match_parent"
17         android:layout_height="wrap_content"
18         android:text="保存资产文件到内部存储"
19         android:onClick="bt4_OnClick"/>
20 
21     <ImageView
22         android:layout_width="wrap_content"
23         android:layout_height="30dp"
24         android:id="@+id/iv_1"
25         android:src="@drawable/f9"/>
26 
27     <Button
28         android:layout_width="match_parent"
29         android:layout_height="wrap_content"
30         android:text="设置图片指向内部存储"
31         android:onClick="bt5_OnClick"/>
32 
33 
34 
35 
36 
37 </LinearLayout>
图片手机内部存储

相关文章:

  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-11-30
  • 2021-09-20
猜你喜欢
  • 2021-11-27
  • 2021-09-12
  • 2022-01-17
  • 2021-05-26
  • 2022-01-15
  • 2022-01-14
  • 2022-01-07
相关资源
相似解决方案