当前位置: 移动技术网 > IT编程>移动开发>Android > Android之PhotoView使用

Android之PhotoView使用

2019年04月08日  | 移动技术网IT编程  | 我要评论

蓝瘦香菇食堂热捧,xwjr,何权

文章大纲

一、什么是photoview
二、代码实战
三、项目源码下载

一、什么是photoview

  一款 imageview 展示框架,支持缩放,响应手势,位于图片排行榜的第五位,photoview 与上面不同的是图片的展示功能,可以实现类似微信头像的放大功能,还有就是很多 app 的图片显示响应手势按压式如何是现实的,这里 photoview 将都可以轻松实现。

二、代码实战

1. 添加依赖

    implementation 'com.bm.photoview:library:1.4.1'

2. 添加图片资源

实际项目中,该图片可能是通过网络请求获取的。

 

3. 编写xml代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".mainactivity">

    <com.bm.library.photoview
        android:id="@+id/photoview"
        android:src="@drawable/test"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</android.support.constraint.constraintlayout>

3. 编写activity代码

public class mainactivity extends appcompatactivity {

    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);

        photoview photoview = findviewbyid(r.id.photoview);

        photoview.enable();//设置是否允许缩放,默认是不允许的
    }
}

4. 运行结果如下

 
 

三、项目源码下载

链接:https://pan.baidu.com/s/1fmedq93ghjpc4a70mh8p9q
密码:kkss

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网