功能:

  • 正常加载图片
  • 双击放大
  • 手势随意缩放
  • 随意拖动查看图片每一个角落
  • 结合其他设置可实现翻转
  • 1:本地图片加载

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/id_loc"
        android:scaleType="fitXY"
        />
    <uk.co.senab.photoview.PhotoView
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/id_myimg"/>

    第一种方法:

     //本地加载方法一
        // 设置图片
        Drawable bitmap = getResources().getDrawable(R.mipmap.ic_launcher);
        loc.setImageDrawable(bitmap);
        // 连接在photoview中
        PhotoViewAttacher mAttacher = new PhotoViewAttacher(loc);
        mAttacher.update();//更新 

    第二种

    //本地方法加载二
        PhotoViewAttacher mAttacher;
        mAttacher = new PhotoViewAttacher(loc);
        iv.setImageBitmap(bitmap);
        Glide.with(this).load(R.mipmap.ic_launcher).asBitmap().into(loc);
        mAttacher.update();

     2:网络图片加载

    对于网络也是可以用ImageView和PhotoView两种

    把ImageView或者PhotoView的对象名直接添加到display中就OK 了。    

    //加载网络图片
        ImageLoader loader= ImageLoader.getInstance();
        loader.init(ImageLoaderConfiguration.createDefault(ImageTest.this));//loader初始化
        loader.displayImage("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1529211252&di=1414331e22239ecb5730cbbd0f3793eb&src=http://pic154.nipic.com/file/20180114/26629113_090329120799_2.jpg",loc);//展示图片

    看一下源码,其实他也是继承了ImageView

    /**
       * Adds display image task to execution pool. Image will be set to ImageView when it's turn. <br/>
       * Default {@linkplain DisplayImageOptions display image options} from {@linkplain ImageLoaderConfiguration
       * configuration} will be used.<br />
       * <b>NOTE:</b> {@link #init(ImageLoaderConfiguration)} method must be called before this method call
       *
       * @param uri    Image URI (i.e. "http://site.com/image.png", "file:///mnt/sdcard/image.png")
       * @param imageView {@link ImageView} which should display image
       * @throws IllegalStateException  if {@link #init(ImageLoaderConfiguration)} method wasn't called before
       * @throws IllegalArgumentException if passed <b>imageView</b> is null
       */
      public void displayImage(String uri, ImageView imageView) {
        displayImage(uri, new ImageViewAware(imageView), null, null, null);
      }
posted on 2021-01-25 20:35  在下程序猿  阅读(230)  评论(0编辑  收藏  举报