android 图片缩放,github开源库,PhotoView 使用

1.PhotoView,使用介绍:

支持捏合,点击放大缩小。支持在ViewPager中翻页预览图片。

2.开发集成步骤:
1)首先,在github下载源码包
连接地址:https://github.com/chrisbanes/PhotoView
在下载压缩包中找到library里面的src文件源码,copy在自己的项目工程目录下;
2)MainActivity.java

package com.example.chenkui.photoviewdome;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.IOException;
import java.io.InputStream;

import photoview.PhotoView;
import photoview.PhotoViewAttacher;

public class MainActivity extends AppCompatActivity {
    private Button imageViewBtn, photoViewBtn;
    private ImageView imgView;
    private PhotoView photoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {

        imageViewBtn = (Button) findViewById(R.id.imageViewBtn);
        photoViewBtn = (Button) findViewById(R.id.photoViewBtn);
        imgView = (ImageView) findViewById(R.id.imgView);
        photoView = (PhotoView) findViewById(R.id.photoView);


        imageViewBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                photoView.setVisibility(View.GONE);
                imgView.setVisibility(View.VISIBLE);
                new PhotoViewAttacher(imgView);
                imgView.setImageBitmap(getAssets("photo.png"));


            }
        });

        photoViewBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imgView.setVisibility(View.GONE);
                photoView.setVisibility(View.VISIBLE);
                photoView.setImageBitmap(getAssets("photoview.jpg"));


            }
        });


    }

    private Bitmap getAssets(String assetsPath) {
        Bitmap bitmap = null;
        try {
            InputStream in = getAssets().open(assetsPath);
            bitmap = BitmapFactory.decodeStream(in);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }


}

activity_main.xml

<?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"
>
    <Button android:id="@+id/imageViewBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ImageView"
            android:textSize="34dp"/>
    <Button android:id="@+id/photoViewBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="photoView"
            android:textSize="34dp"/>

    <ImageView
        android:id="@+id/imgView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"/>
    <photoview.PhotoView
        android:id="@+id/photoView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"/>


</LinearLayout>

资源库整理源码,直接使用 http://download.csdn.net/detail/qq_26337701/9613167

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值