---
title: "在Android模拟器中使用SDCARD，使用ImageView显示SDCARD上的图片"
author: "zwm"
date: "2011-02-12T12:03:27Z"
tags: []
categories: ["移动开发"]
slug: "android-sdcard-imageview-sdcard"
draft: false
lastmod: "2011-02-12T12:03:27Z"
id: 904422
url: "https://zwm.iteye.com/blog/904422"
---

1、创建AVD时，指定sdcard选项 yes  
2、上传图片命令：  
adb push a.png sdcard/a.png  
3、启动模拟器后，选择Dev Tools/Media Scanner操作

JAVA代码：  
        ImageView view = (ImageView)findViewById(R.id.imview);  
        String img = "/sdcard/a.png";   
        BitmapFactory.Options options = new BitmapFactory.Options();  
        options.inSampleSize = 2;  
        Bitmap bm = BitmapFactory.decodeFile(img, options);  
        view.setImageBitmap(bm);

 

布局文件：  
&lt;?xml version="1.0" encoding="utf-8"?&gt;  
&lt;LinearLayout xmlns:android="[http://schemas.android.com/apk/res/android](http://schemas.android.com/apk/res/android)"  
 android:orientation="vertical" android:layout\_width="fill\_parent"  
 android:layout\_height="fill\_parent"&gt;  
 &lt;ImageView android:id="@+id/imview"  
 android:layout\_width="50dp"  
 android:layout\_height="50dp" android:layout\_gravity="center"  
 /&gt;  
&lt;/LinearLayout&gt;