今天看了今日头条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