欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

Android之PhotoView使用(原创)

发布时间:2023/12/10 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Android之PhotoView使用(原创) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章大纲

一、什么是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

转载于:https://www.cnblogs.com/WUXIAOCHANG/p/10667037.html

总结

以上是生活随笔为你收集整理的Android之PhotoView使用(原创)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。