ImageView是如何使用的

来源:互联网 发布:java架构师视频教程 编辑:程序博客网 时间:2024/05/16 11:37

在manifest项目清单文件中加入ImageView控件如下:

    <ImageView        android:id="@+id/imt_photo"        android:layout_width="fill_parent"        android:layout_height="fill_parent"       android:layout_marginLeft="0dp"       android:layout_marginRight="0dp"        android:layout_marginTop="0dp" >    </ImageView>

具体在Activity中使用如下:


    private ImageView img_photo;    img_photo = (ImageView) findViewById(R.id.imt_photo);    img_photo.setImageBitmap(pic); // 这个ImageView是拍照完成后显示图片    private static String photoPath = "/sdcard/AnBo/";    private static String photoName = photoPath + "laolisb.jpg";    BitmapFactory.Options op = new BitmapFactory.Options();    op.inSampleSize = 4; // 这个数字越大,图片大小越小,越不清晰    Bitmap pic = null;    pic = BitmapFactory.decodeFile(photoName, op);   //從指定地址獲取圖片信息    img_photo.setImageBitmap(pic); // 將圖片信息顯示出來

使用上很簡單!



还有另外一种做法:
这里写图片描述



FR:徐海濤(Hunk Xu)

1 0