爲了解決圖片的縮放和gif格式的圖片顯示問題,這裏採用了開源庫PhototView(處理圖片縮放問題)和GifView(顯示gif格式圖片)。
PhototView下載路徑,GifView下載路徑,Demo下載路徑
(1)PhotoView加載本地圖片
<span style="font-size:14px;">/**
* PhotoView 加載本地圖片
*/
private ImageView mImageView;
<span style="background-color: rgb(255, 255, 255);"><span style="color:#ff0000;">private PhotoViewAttacher mPhotoViewAttacher;</span></span>
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);
<span style="color:#ff0000;">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();
}
}</span>
(2)、PhotoView加載網絡圖片:
<span style="font-size:14px;">/**
* PhotoView 加載網絡圖片
*/
<span style="color:#ff0000;">private PhotoView mImageView;
private PhotoViewAttacher mPhotoViewAttacher;</span>
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);
<span style="color:#ff0000;">mPhotoViewAttacher = new PhotoViewAttacher(mImageView);
mImageLoader = ImageLoader.getInstance();
mImageLoader.displayImage(URL, mImageView);
mImageView.setOnPhotoTapListener(new OnPhotoTapListener() {
</span>
@Override
public void onPhotoTap(View arg0, float arg1, float arg2) {
// TODO Auto-generated method stub
}
});
}</span>
佈局文件:
<span style="font-size:14px;"><?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>
<span style="font-size:14px;"><span style="color:#ff0000;">private GifView mGifView;</span>
@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);
//加載本地圖片
<span style="color:#ff0000;">mGifView.setGifImage(R.drawable.gifview);</span>
}</span>
佈局文件:
<span style="font-size:14px;"><?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>