public class ScaleGesture implements OnScaleGestureListener {

private float beforeFactor;
private float mPivotX;
private float mPivotY;
private View mVSouce;
private boolean isFillAfter;

public void setSourceView(View destinyView) {
mVSouce = destinyView;
}

@Override
public boolean onScale(ScaleGestureDetector detector) {
if (checkIsNull()) {
return false;
}
final float factor = detector.getScaleFactor();
Animation animation = new ScaleAnimation(beforeFactor, factor,
beforeFactor, factor, mPivotX, mPivotY);
animation.setFillAfter(true);
mVSouce.startAnimation(animation);
beforeFactor = factor;
return false;
}

@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
if (checkIsNull()) {
return false;
}
beforeFactor = 1f;
mPivotX = detector.getFocusX() - mVSouce.getLeft();
mPivotY = mVSouce.getTop() + (mVSouce.getHeight() >> 1);
return true;
}

@Override
public void onScaleEnd(ScaleGestureDetector detector) {
if (checkIsNull()) {
return;
}
final float factor = detector.getScaleFactor();
final int nWidth = (int) (mVSouce.getWidth() * factor);
final int nHeight = (int) mVSouce.getHeight();
final int nLeft = (int) (mVSouce.getLeft() - ((nWidth - mVSouce
.getWidth()) * (mPivotX / mVSouce.getWidth())));
final int nTop = (int) mVSouce.getTop();
if (isFillAfter) {
mVSouce.layout(nLeft, nTop, nLeft + nWidth, nTop + nHeight);
}
// MUST BE CLEAR ANIMATION. OTHERWISE WILL BE FLICKER
// if can not clear animation the layout will keep the size
// mVSouce.clearAnimation();
}

public boolean checkIsNull() {
return mVSouce == null ? true : false;
}

/**
 * if parameter is true that keeping same scale when next scaling.
 * 
 * @param isFill
 */
public void setFillAfter(boolean isFill) {
isFillAfter = isFill;
}
}
/*在activity里面定义变量*/
ScaleGesture sg = new ScaleGesture();
ScaleGestureDetector detector;
/*在oncreat方法里面*/
detector = new ScaleGestureDetector(你要缩放的view.getContext(), sg);
sg.setSourceView(你要缩放的view);
/*可以实现缩放,但移动view实现的不好,可以使用scrollby实现移动查看*/

ScaleGestureDetector缩放view的更多相关文章

  1. android的ScaleGestureDetector缩放类详解

    文章由多出组合,它们来自: http://elvajxw.iteye.com/blog/1308452 http://www.cnblogs.com/lknlfy/archive/2012/03/11 ...

  2. 缩放手势 ScaleGestureDetector 源码解析,这一篇就够了

    其实在我们日常的编程中,对于缩放手势的使用并不是很经常,这一手势主要是用在图片浏览方面,比如下方例子.但是(敲重点),作为 Android 入门的基础来说,学习 ScaleGestureDetecto ...

  3. View的平移、缩放、旋转以及位置、坐标系

    原创 2015年05月12日 13:15:29 标签: Android / Scroll / Scale / Translation / Rotation 24733 Android开发中,经常会接触 ...

  4. 缩放系列(三):一个可以手势缩放、拖拽、旋转的layout

    弄了一个下午,终于搞出来了,PowerfulLayout 下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像b ...

  5. 缩放系列(二):所有子控件也随着缩放、手势缩放、多点触控layout

    下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像button有可被点击的功能,缩放后不能丢失该功能) 运行效 ...

  6. Android查缺补漏(View篇)--自定义 View 的基本流程

    View是Android很重要的一部分,常用的View有Button.TextView.EditView.ListView.GridView.各种layout等等,开发者通过对这些View的各种组合以 ...

  7. Android 手势识别—缩放

    上一篇讲解了手势识别中的点击和双击事件的识别,用到的是GestureDetector类和GestureDetectorCompat类,用于监听用户触摸屏幕中的简单动作. 缩放 基本用法如下,可以通过缩 ...

  8. 详解iOS开发之自定义View

    iOS开发之自定义View是本文要将介绍的内容,iOS SDK中的View是UIView,我们可以很方便的自定义一个View.创建一个 Window-based Application程序,在其中添加 ...

  9. 微信小程序movable-view移动图片和双指缩放

    先从movable-view开始说起吧. movable-view是小程序自定义的组件.其描述为:"可移动的视图容器,在页面中可以拖拽滑动". 官方文档地址:https://mp. ...

随机推荐

  1. 如何编写好的jQuery代码

    本文就是自己看,如果您不小心进到了这里,请看源处,是这个作者翻译的:http://blog.sae.sina.com.cn/archives/4157 讨论jQuery和javascript性能的文章 ...

  2. 1452: [JSOI2009]Count - BZOJ

    Description Input Output Sample Input Sample Output 1 2HINT 一开始还想什么离线做,其实不用,空间足够,我们直接开100个二维树状数组,然后就 ...

  3. c++ 从标注输入流读取行

    #include <string.h> #include <iostream> #include <vector> #include <stdio.h> ...

  4. Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  5. unity3d GameObject.Find 严格区分大小写的

    GameObject.Find 查找 static function Find (name : string) : GameObject Description描述 Finds a game obje ...

  6. **【ci框架】PHP的CI框架集成Smarty的最佳方式

    因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...

  7. SDUT2241计算组合数C(n,m)(组合数)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2241 这个题的代码适应性也挺强,但这个题倒不适 ...

  8. 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement

    这题当时竟然没看啊…… 找规律:求和m+m+m-1+m-1+……前n项 ;}

  9. C Primer Plus之高级数据表示

     抽象数据类型(ADT)    类型是由什么组成?一个类型(type)指定两类信息:一个属性集和一个操作集. 所以您想定义一个新的数据类型.首先,您需要提供存储数据的方式,可能是通过设计一个结构.第二 ...

  10. 20. atoi函数

    /* 输入一个表示整数的字符串,把该字符串转换成整数并输出 */ #include<iostream> #include<string> using namespace std ...