Android 图片查看器实现 PhotoView + ViewPager

本文介绍了如何使用PhotoView框架和ViewPager在Android中实现图片查看器功能,参照今日头条APP的图片查看效果。通过引入PhotoView实现图片缩放,使用Slider框架实现界面滑动退出,如上下滑动退出界面,不依赖手机返回键。
摘要由CSDN通过智能技术生成

今天看了今日头条APP的图片查看的效果,就自己实现了一下。

效果如下


首先引入两个库

一个是图片缩放的功能:PhotoView框架

compile 'com.github.chrisbanes:PhotoView:1.2.6'

一个界面滑动退出效果(比如自己滑动空白区域,就退出界面,而不用按手机返回键。我这里实现上下滑动退出界面)Slider框架

compile 'com.komi.slider:slider:0.4.0'

项目目录如下:


布局文件activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.gps.MainActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="120dp">

        <ImageView
            android:id="@+id/photo_1"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="@mipmap/photo_1"/>

        <ImageView
            android:id="@+id/photo_2"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_weight="1"
            android:la
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值