bm-x / PhotoView

图片浏览缩放控件
2.63k stars 539 forks source link

你好 请问您的库有没有类似于微博浏览长图的时候 长图左右满屏,但从顶部开始显示的缩放模式 #44

Open aricguo opened 7 years ago

aricguo commented 7 years ago

你好 请问您的库有没有类似于微博浏览长图的时候 长图左右满屏,但从顶部开始显示的缩放模式 谢谢回复

bm-x commented 7 years ago

使用scaletype

aricguo commented 7 years ago

尝试过scaleType 但想center_crop图片只能从中间显示,并不能保证从顶部开始显示 还望指教

bm-x commented 7 years ago

fit_start

aricguo commented 7 years ago

尝试了fit_start 但是图片却被缩放到屏幕范围内大小,而且从最左端(应该就是start的意思)开始显示 导致右边空了一块区域 并不是期望的效果

ayuhani commented 7 years ago

@bm-x 使用了 fit_start, 长图显示正常,从顶部开始显示,但是小图显示也在顶部,触摸一下小图会立刻跑到屏幕中间;使用 fit_center, 小图可以正常显示,长图只能从中间显示。

ayuhani commented 7 years ago

@Guoooooo 请问你这个问题解决了吗?

bm-x commented 7 years ago

额?我看看,应该没问题的额

ayuhani commented 7 years ago

@bm-x photoView的宽高设置的都是match,高度如果设置wrap的话,发现photoview的高度不是和图片自适应的,有时候高度比图片高,有时候高度比图片低

aricguo commented 7 years ago

@bm-x 没有解决 之后使用了webview 交互效果差了一些

wpe0wpe0wpe commented 6 years ago

你可以用这个扩大图片和定位显示 photo.setScale(1.0f, 0, 150, true); 第一个参数是扩大的倍数,最多是3.0f,作者大神规定的。第三个参数就是Y轴上移的单位,0就是顶图。需要扩大的倍数可以根据屏幕宽度、像素比,比如1080等对应扩大,主要是这个问题出现在长图加载,一般是view.draw出来的bitmap遇到的问题

vickyleu commented 6 years ago

使用fitStart并且稍微修改一下animfrom就好了

vickyleu commented 6 years ago

fun animateFrom(imageInfo: ImageInfo) {

    if (isInit) {
        reset()

        val mine = info

        val scaleX = imageInfo.mImgRect.width() / mine.mImgRect.width()
        val scaleY = imageInfo.mImgRect.height() / mine.mImgRect.height()
        val scale = if (scaleX < scaleY) scaleY else scaleX//choose the max one

        //设置位置之前先检查是否有 目标PhotoView是否有 margin,或者其父对应的padding
        val parent = parent as ViewGroup
        val params = layoutParams as ViewGroup.MarginLayoutParams
        val ocx = imageInfo.mRect.left + imageInfo.mRect.width() / 2 - params.leftMargin.toFloat() - parent.paddingLeft.toFloat()
        val ocy = imageInfo.mRect.top + imageInfo.mRect.height() / 2 - params.topMargin.toFloat() - parent.paddingTop.toFloat()

        mAnimaMatrix.reset()
        mAnimaMatrix.postTranslate(-mBaseRect.left + params.leftMargin.toFloat() + parent.paddingLeft.toFloat(),
                -mBaseRect.top + params.topMargin.toFloat() + parent.paddingTop.toFloat())

        val parentYTrans=mBaseRect.height() / 2 - params.topMargin.toFloat() - parent.paddingTop.toFloat()
        if (Math.abs(parentYTrans)<=Math.abs(height)){
            mAnimaMatrix.postTranslate(ocx - mBaseRect.width() / 2 - params.leftMargin.toFloat() - parent.paddingLeft.toFloat(),
                    ocy -parentYTrans)
        }

        mAnimaMatrix.postScale(scale, scale, ocx, ocy)
        mAnimaMatrix.postRotate(imageInfo.mDegrees, ocx, ocy)
        executeTranslate()

        mScaleCenter.set(ocx, ocy)
        mRotateCenter.set(ocx, ocy)

        if (Math.abs(parentYTrans)>Math.abs(height)){
            mTranslate.withTranslate(0, 0, (mScreenCenter.x - ocx).toInt(),(parentYTrans-ocy).toInt())
        }else{
            mTranslate.withTranslate(0, 0, (mScreenCenter.x - ocx).toInt(), (mScreenCenter.y - ocy).toInt())
        }
        mTranslate.withScale(scale, 1f)
        mTranslate.withRotate(imageInfo.mDegrees.toInt(), 0)

        if (imageInfo.mWidgetRect.width() < imageInfo.mImgRect.width() || imageInfo.mWidgetRect.height() < imageInfo.mImgRect.height()) {
            var clipX = imageInfo.mWidgetRect.width() / imageInfo.mImgRect.width()
            var clipY = imageInfo.mWidgetRect.height() / imageInfo.mImgRect.height()
            clipX = if (clipX > 1) 1f else clipX
            clipY = if (clipY > 1) 1f else clipY

            val c = if (imageInfo.mScaleType == ImageView.ScaleType.FIT_START) START() else if (imageInfo.mScaleType == ImageView.ScaleType.FIT_END) END() else OTHER()

            mTranslate.withClip(clipX, clipY, 1 - clipX, 1 - clipY, defaultAnimaDuring / 3, c)

            mTmpMatrix.setScale(clipX, clipY, (mImgRect.left + mImgRect.right) / 2, c.calculateTop())
            mTmpMatrix.mapRect(mTranslate.mClipRect, mImgRect)
            mClip = mTranslate.mClipRect
        }

        mTranslate.start()
    } else {
        mImageInfo = imageInfo
        mInfoTime = System.currentTimeMillis()
    }
}