第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

我什么我跟你的一樣運(yùn)行不了大神

package newer.com.imageviewkk;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

/**
* Created by Administrator on 2015-6-11.
*/
public class ZoomImageView extends ImageView implements ViewTreeObserver.OnGlobalLayoutListener, ScaleGestureDetector.OnScaleGestureListener, View.OnTouchListener {
? ?private Boolean mOnce;
? ?/**
? ? * 初始化縮放的值
? ? */
? ?private float mInitScale;
? ?/**
? ? * 雙擊放大值到達(dá)的值
? ? */
? ?private float mMidScale;
? ?/**
? ? * 放大的極限
? ? */
? ?private float mMaxScale;
? ?private Matrix mScaleMatrix;
? ?/**
? ? * 捕獲用戶多點(diǎn)指控
? ? */
? ?private ScaleGestureDetector mScaleGestureDetector;

? ?public ZoomImageView(Context context) {
? ? ? ?this(context, null);
? ?}

? ?public ZoomImageView(Context context, AttributeSet attrs) {
? ? ? ?this(context, attrs, 0);
? ?}

? ?public ZoomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
? ? ? ?super(context, attrs, defStyleAttr);
? ? ? ?mScaleMatrix = new Matrix();
? ? ? ?setScaleType(ScaleType.MATRIX);
? ? ? ?mScaleGestureDetector = new ScaleGestureDetector(context, this);
? ? ? ?setOnTouchListener(this);
? ?}

? ?@Override
? ?protected void onAttachedToWindow() {
? ? ? ?super.onAttachedToWindow();
? ? ? ?//注冊
? ? ? ?getViewTreeObserver().addOnGlobalLayoutListener(this);
? ?}

? ?@Override
? ?protected void onDetachedFromWindow() {
? ? ? ?super.onDetachedFromWindow();
? ? ? ?//移除
? ? ? ?getViewTreeObserver().removeGlobalOnLayoutListener(this);
? ?}

? ?/**
? ? * 獲取加載完成的圖片
? ? */
? ?@Override
? ?public void onGlobalLayout() {
? ? ? ?if (!mOnce) {
? ? ? ? ? ?//得到控件的寬和高
? ? ? ? ? ?int width = getWidth();
? ? ? ? ? ?int height = getHeight();
? ? ? ? ? ?//得到我們的圖片,以及寬和高
? ? ? ? ? ?Drawable d = getDrawable();
? ? ? ? ? ?if (d == null) {
? ? ? ? ? ? ? ?return;
? ? ? ? ? ?}
? ? ? ? ? ?int dw = d.getIntrinsicWidth();
? ? ? ? ? ?int dh = d.getIntrinsicHeight();
? ? ? ? ? ?//設(shè)置縮放值
? ? ? ? ? ?float scale = 1.0f;
? ? ? ? ? ?/**
? ? ? ? ? ? * ?如果圖片的寬度大于控件寬度,但是高度高于小于控件寬度;我們將其縮小
? ? ? ? ? ? *
? ? ? ? ? ? */
? ? ? ? ? ?if (dw > width && dh < height) {
? ? ? ? ? ? ? ?scale = width * 1.0f / dw;
? ? ? ? ? ?}
? ? ? ? ? ?/**
? ? ? ? ? ? * ?如果圖片的寬度大于控件寬度,但是高度高于小于控件寬度;我們將其縮小
? ? ? ? ? ? *
? ? ? ? ? ? */
? ? ? ? ? ?if (dh > height && dh < height) {
? ? ? ? ? ? ? ?scale = height * 1.0f / dh;
? ? ? ? ? ?}
? ? ? ? ? ?/**
? ? ? ? ? ? * ?如果圖片的寬度大于控件寬度,但是高度高于小于控件寬度;我們將其縮小
? ? ? ? ? ? *
? ? ? ? ? ? */
? ? ? ? ? ?if ((dw > width && dh > height) || (dw < width && dh < height)) {

? ? ? ? ? ? ? ?scale = Math.min(width * 1.0f / dw, height * 1.0f / dw);

? ? ? ? ? ?}
? ? ? ? ? ?/**
? ? ? ? ? ? * 等到初始化的值比例
? ? ? ? ? ? */
? ? ? ? ? ?mInitScale = scale;
? ? ? ? ? ?mMaxScale = mInitScale * 4;
? ? ? ? ? ?mMidScale = mInitScale * 2;

? ? ? ? ? ?//將圖片移動至控件的中心
? ? ? ? ? ?int dx = getWidth() / 2 - dw / 2;
? ? ? ? ? ?int dy = getHeight() / 2 - dh / 2;

? ? ? ? ? ?mScaleMatrix.postTranslate(dx, dy);
? ? ? ? ? ?//縮放圖片
? ? ? ? ? ?mScaleMatrix.postScale(mInitScale, mInitScale, width / 2, height / 2);
? ? ? ? ? ?setImageMatrix(mScaleMatrix);
? ? ? ? ? ?mOnce = true;
? ? ? ?}
? ?}

? ?/**
? ? * 獲取當(dāng)前圖片的縮放值
? ? *
? ? * @return
? ? */
? ?public float getScale() {
? ? ? ?float[] values = new float[9];
? ? ? ?mScaleMatrix.getValues(values);
? ? ? ?return values[Matrix.MSCALE_X];

? ?}

? ?/**
? ? * 縮放的區(qū)間
? ? * initScale maxScale
? ? * 縮放比例
? ? *
? ? * @param detector
? ? * @return
? ? */
? ?@Override
? ?public boolean onScale(ScaleGestureDetector detector) {
? ? ? ?//拿到縮放值
? ? ? ?float scale = getScale();
? ? ? ?float scaleFactor = detector.getScaleFactor();
? ? ? ?if (getDrawable() == null)
? ? ? ? ? ?return true;

? ? ? ?//縮放范圍的控制
? ? ? ?if ((scale < mMaxScale && scaleFactor > 1.0f) || (scale > mInitScale && scaleFactor < 1.0f)) {

? ? ? ? ? ?if (scale * scaleFactor < mInitScale) {
? ? ? ? ? ? ? ?scaleFactor = mInitScale / scale;

? ? ? ? ? ?}

? ? ? ? ? ?if (scale * scaleFactor > mMaxScale) {
? ? ? ? ? ? ? ?scale = mMaxScale / scale;

? ? ? ? ? ?}
? ? ? ? ? ?//縮放
? ? ? ? ? ?mScaleMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
? ? ? ? ? ?checkBorderAndCenterWhenScale();
? ? ? ? ? ?setImageMatrix(mScaleMatrix);

? ? ? ?}
? ? ? ?return true;
? ?}

? ?/**
? ? * 獲得圖片放大縮小以后的寬和高,以及l(fā),r,t,b
? ? *
? ? * @return
? ? */
? ?private RectF getMatrixRectF() {
? ? ? ?Matrix matrix = mScaleMatrix;
? ? ? ?RectF rectF = new RectF();
? ? ? ?Drawable d = getDrawable();
? ? ? ?if (d != null) {
? ? ? ? ? ?rectF.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
? ? ? ? ? ?matrix.mapRect(rectF);
? ? ? ?}
? ? ? ?return rectF;
? ?}

? ?/**
? ? * 在縮放的時候進(jìn)行邊界控件已及我們的位置控制
? ? */
? ?private void checkBorderAndCenterWhenScale() {
? ? ? ?RectF rect = getMatrixRectF();
? ? ? ?float deltaX = 0;
? ? ? ?float deltaY = 0;
? ? ? ?int width = getWidth();
? ? ? ?int height = getHeight();
//縮放時進(jìn)行邊界檢測,防止出現(xiàn)白邊
? ? ? ?if (rect.width() >= width) {
? ? ? ? if (rect.left >0){
? ? ? ? ? ? deltaX = -rect.left;
? ? ? ? }
? ? ? ? ? ?if (rect.right <width){
? ? ? ? ? ? ? ?deltaX = width - rect.right;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?if (rect.height() >= height){
? ? ? ? ? ?if (rect.top >0){
? ? ? ? ? ? ? ?deltaY = -rect.top;
? ? ? ? ? ?}
? ? ? ? ? ?if (rect.bottom <height){
? ? ? ? ? ? ? ?deltaY = height - rect.bottom;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?//如果寬度或者高度小于控件的寬或者高;則讓其居中
? ? ? ?if (rect.width() <width){
? ? ? ? ? ?deltaX = width /2f -rect.right + rect.width() /2f;

? ? ? ?}
? ? ? ?if (rect.height() < height){
? ? ? ? ? ? deltaY = height /2f -rect.bottom +rect.height()/2f;
? ? ? ?}
? ? ? ?mScaleMatrix.postTranslate(deltaX,deltaY);
? ?}

? ?@Override
? ?public boolean onScaleBegin(ScaleGestureDetector detector) {
? ? ? ?return true;
? ?}

? ?@Override
? ?public void onScaleEnd(ScaleGestureDetector detector) {

? ?}

? ?//------------------------------------
? ?@Override
? ?public boolean onTouch(View v, MotionEvent event) {
? ? ? ?mScaleGestureDetector.onTouchEvent(event);
? ? ? ?return true;
? ?}
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
? ?xmlns:android="http://schemas.android.com/apk/res/android"

? ?android:layout_width="match_parent"
? ?android:layout_height="match_parent">

? ?<newer.com.imageviewkk.ZoomImageView
? ? ? ?android:layout_width="wrap_content"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:src="@drawable/a"
? ? ? ?android:scaleType="matrix"
? ? ? ?></newer.com.imageviewkk.ZoomImageView>

?
</RelativeLayout>


正在回答

3 回答

scale = Math.min(width *1.0f/dw, height*1.0f/dh);

0 回復(fù) 有任何疑惑可以回復(fù)我~

壓縮圖片寬高的第二個判斷條件錯了

0 回復(fù) 有任何疑惑可以回復(fù)我~

我的也是?。。。。。。。。。?!

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
打造個性的圖片預(yù)覽與多點(diǎn)觸控
  • 參與學(xué)習(xí)       23116    人
  • 解答問題       74    個

實現(xiàn)圖片自由縮放與多點(diǎn)觸控效果,對Matrix以及手勢檢測API深入學(xué)習(xí)

進(jìn)入課程

我什么我跟你的一樣運(yùn)行不了大神

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號