PhotoView点击图片放大缩小

 

新建一个modul

里面加入这几个类(前提必须把这个modul变成可依赖的Library)

首先去build.gradle首行改为

apply plugin: 'com.android.library'

删除defaultConfig里面的appliaction要不然会报错

错误:Library....

地址:http://git.oschina.net/TianBinRui/phopoview/tree/master

Compat
CustomGestureDetector
OnGestureListener
OnMatrixChangedListener
OnOutsidePhotoTapListener
OnPhotoTapListener
OnScaleChangedListener
OnSingleFlingListener
OnViewDragListener
OnViewTapListener
PhotoView
PhotoViewAttacher
Util

用另一个modul依赖第一个modul加入依赖

首先添加联网权限

<uses-permission android:name="android.permission.INTERNET" />

在xml中添加属性(financialshare.com.ptpview.PhotoView路劲)

<financialshare.com.ptpview.PhotoView
    android:id="@+id/iv_photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

在Activity中添加以下代码

PhotoView photoView = (PhotoView) findViewById(R.id.iv_photo);
Picasso.with(this)
        .load("http://img.1985t.com/uploads/attaches/2017/06/122920-Qr51Tnt.jpg")
        .into(photoView);
photoView.setOnPhotoTapListener(new OnPhotoTapListener() {
    @Override
    public void onPhotoTap(ImageView view, float x, float y) {
        //fullScreen();
    }
});
fullScreen();
public void fullScreen() {

    // BEGIN_INCLUDE (get_current_ui_flags)
    // The UI options currently enabled are represented by a bitfield.
    // getSystemUiVisibility() gives us that bitfield.
    int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
    int newUiOptions = uiOptions;
    // END_INCLUDE (get_current_ui_flags)
    // BEGIN_INCLUDE (toggle_ui_flags)
    boolean isImmersiveModeEnabled = isImmersiveModeEnabled();
    if (isImmersiveModeEnabled) {
        Log.i("TEST", "Turning immersive mode mode off. ");
    } else {
        Log.i("TEST", "Turning immersive mode mode on.");
    }

    // Navigation bar hiding:  Backwards compatible to ICS.
    if (Build.VERSION.SDK_INT >= 14) {
        newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }

    // Status bar hiding: Backwards compatible to Jellybean
    if (Build.VERSION.SDK_INT >= 16) {
        newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
    }

    // Immersive mode: Backward compatible to KitKat.
    // Note that this flag doesn't do anything by itself, it only augments the behavior
    // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
    // all three flags are being toggled together.
    // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
    // Sticky immersive mode differs in that it makes the navigation and status bars
    // semi-transparent, and the UI flag does not get cleared when the user interacts with
    // the screen.
    if (Build.VERSION.SDK_INT >= 18) {
        newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    }

    getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    //END_INCLUDE (set_ui_flags)
}
private boolean isImmersiveModeEnabled() {
    return ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
}

转载于:https://my.oschina.net/u/3486497/blog/994580

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值