goback add

在ImageView中加载SD卡上的图片资源

3131 点击·0 回帖
灯火互联
楼主


1. <ImageView  
2.     Android:id="@+id/imgView"  
3.     Android:layout_width="fill_parent"  
4.     Android:layout_height="fill_parent"  
5.   />
1. public void onCreate(Bundle savedInstanceState) {
2.         super.onCreate(savedInstanceState);
3.         setContentView(R.layout.main);
4.          
5.         Button btn = (Button)findViewById(R.id.btn_b);
6.         btn.setOnClickListener(new View.OnClickListener() {
7.  
8.             @Override
9.             public void onClick(View v) {
10.                 ImageView view = (ImageView)findViewById(R.id.imgView);
11.                 String img = "/mnt/extsd/11.png";  
12.                 BitmapFactory.Options options = new BitmapFactory.Options();
13.                 options.inSampleSize = 2;
14.                 Log.i("chen", "============options======="+options);
15.                 Bitmap bm = BitmapFactory.decodeFile(img, options);
16.                 view.setImageBitmap(bm);
17.                
18.             }
19.         });
20.     }
作者:chenshijun0101

喜欢0 评分0