android开发笔记之PhotoView

来源:互联网 发布:mysql汉字转拼音函数 编辑:程序博客网 时间:2024/06/05 04:31

参考资料

1.PhotoView
https://github.com/chrisbanes/PhotoView
2.android studio PhotoView配置与用法
http://blog.csdn.net/vc_bin/article/details/52549771
3.PhotoView开源项目剖析
http://blog.csdn.net/wu928320442/article/details/43056731

Features

  1. Out of the box zooming, using multi-touch and double-tap.
  2. Scrolling, with smooth scrolling fling.
  3. Works perfectly when used in a scrolling parent (such as ViewPager).
  4. Allows the application to be notified when the displayed Matrix has
    changed. Useful for when you need to update your UI based on the
    current zoom/scroll position.
  5. Allows the application to be notified when the user taps on the
    Photo.

Demo

第一步:添加Dependency:

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {    repositories {        maven { url "https://jitpack.io" }    }}

Then, add the library to your module build.gradle

dependencies {    compile 'com.github.chrisbanes:PhotoView:2.0.0'}

第二步:布局文件activity_test_photo_view.xml

<?xml version="1.0" encoding="utf-8"?><ScrollView    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_test_photo_view"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="android.com.debugdemo.TestPhotoView">    <RelativeLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content">        <ImageView            android:id="@+id/image_view"            android:layout_width="wrap_content"            android:layout_height="wrap_content"/>        <com.github.chrisbanes.photoview.PhotoView            android:id="@+id/photo_view"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_below="@id/image_view"            android:layout_marginTop="10dp"/>    </RelativeLayout></ScrollView>

第三步:源码

import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.ImageView;import com.github.chrisbanes.photoview.PhotoView;public class TestPhotoView extends AppCompatActivity {    private ImageView image_view = null;    private PhotoView photo_view = null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_test_photo_view);        init();    }    private void init() {        image_view = (ImageView)findViewById(R.id.image_view);        image_view.setImageResource(R.drawable.image);        photo_view = (PhotoView)findViewById(R.id.photo_view);        photo_view.setImageResource(R.drawable.image);    }}

效果图:

初始图:
这里写图片描述

双击后的效果图:
这里写图片描述

移动后的效果图:
这里写图片描述

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 巴掌大海龟体内取出104片塑料 巴掌大海龟体内取出104片塑料1 巴掌大海龟体内取出104片塑料d 木塑 木塑地板好吗 塑木挂板 木塑线条 木塑发泡板 塑木地板哪个品牌好 塑木材料厂家 木塑模具 塑木生产厂家 中空木塑板 木塑踢脚线 木塑墙板生产线 塑木格栅价格 石塑木地板 什么是木塑板 塑木图片 塑木材料 塑木价格 塑木护栏 塑木花箱 木塑批发 木塑地板价格 塑木地板价格 塑木花箱厂家 塑木廊架价格 塑木花箱价格 塑木廊架 木塑厂家 塑木材料多少钱一平方 塑木天花 塑木多少钱一平米 塑木材料生产厂家 塑木栈道 塑木坐凳 生态木和塑木 石英塑木 塑木花盆 塑木扶手厂家