PhotoView与GifView的使用


为了解决图片的缩放和gif格式的图片显示问题,这里采用了开源库PhototView(处理图片缩放问题)和GifView(显示gif格式图片)。
PhototView下载路径GifView下载路径Demo下载路径

1、PhotoView加载本地图片

/**
 * PhotoView 加载本地图片
 */

private ImageView mImageView;
private PhotoViewAttacher mPhotoViewAttacher;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.photoview_local);
    mImageView = (ImageView) findViewById(R.id.iv_img);
    mPhotoViewAttacher = new PhotoViewAttacher(mImageView);

    try {
        InputStream inputStream = getAssets().open("testPhotoView.jpg");

        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        mImageView.setImageBitmap(bitmap);</span>
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

2、PhotoView加载网络图片:

/**
 * PhotoView 加载网络图片
 */

private PhotoView mImageView;
private PhotoViewAttacher mPhotoViewAttacher;

private ImageLoader mImageLoader;

private  String URL = "http://pic3.nipic.com/20090525/2416945_231841034_2.jpg";


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.photoview_network);

    mImageView = (PhotoView) findViewById(R.id.iv_img);

    mPhotoViewAttacher = new PhotoViewAttacher(mImageView);
    mImageLoader = ImageLoader.getInstance();
    mImageLoader.displayImage(URL, mImageView);

    mImageView.setOnPhotoTapListener(new OnPhotoTapListener() {

        @Override
        public void onPhotoTap(View arg0, float arg1, float arg2) {
            // TODO Auto-generated method stub

        }
    });
}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <uk.co.senab.photoview.PhotoView
        android:id="@+id/iv_img"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout></span>

3、GifView加载本地图片:

private GifView mGifView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.gifview);

    mGifView = (GifView) findViewById(R.id.gifview);
    //加载本地图片
    mGifView.setGifImage(R.drawable.gifview);
}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <com.ant.liao.GifView
        android:id="@+id/gifview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout></span>

文章作者: imtianx
版权声明: 本博客所有文章除特別声明外,均采用 CC BY-NC 4.0 许可协议。转载请注明来源 imtianx !
评论
 上一篇
android开发较好的blog android开发较好的blog
作为初学者,跟着大神的脚步才能成为大神,少走弯路。以下是个人收藏的一些blog。CSDN博客: 郭霖:http://blog.csdn.net/guolin_blog 鸿洋:http://blog.csdn.net/lmj623
下一篇 
android 打开其他应用 android 打开其他应用
在开发中,有时需要在自己的应用中打开其他应用,自己写了两个方法来获取手机上安装的所有应用。这里主要以打开支付宝为例。(1)、获取手机上的所有应用,将其放在一个list中。 private List<PackageInfo> ge
  目录