Android实现手势滑动多点触摸放大缩小图片效果

2019-12-10 19:07:12刘景俊

这个我就不详细讲解了,大家要注意的是水平和垂直方向的速率.

最后我们看下布局,调用也相当简单,也有助于我们添加辅助UI,千万不要忘记写 android:scaleType="fitXY"这句话,不然有时候会出现诡异现象.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:gravity="center" > 
 
  <com.jj.drag.DragImageView 
    android:id="@+id/div_main" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    android:scaleType="fitXY" 
    /> 
 
</LinearLayout> 

在Acitivity中调用:

/** 测量状态栏高度 **/ 
    viewTreeObserver = dragImageView.getViewTreeObserver(); 
    viewTreeObserver 
        .addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
 
          @Override 
          public void onGlobalLayout() { 
            if (state_height == 0) { 
              // 获取状况栏高度 
              Rect frame = new Rect(); 
              getWindow().getDecorView() 
                  .getWindowVisibleDisplayFrame(frame); 
              state_height = frame.top; 
              dragImageView.setScreen_H(window_height-state_height); 
              dragImageView.setScreen_W(window_width); 
            } 
 
          } 
        }); 

以上就是全部实现.最后我们看下实现的效果吧.

原图大小  

     Android实现手势滑动多点触摸放大缩小图片效果