android 加载长图大图,Android ImageView+Glide实现加载长图片(适合单张图片)

实现效果:

d5cc240fdb27

image.png

d5cc240fdb27

image.png

布局实现:

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/ivImg"

android:adjustViewBounds="true"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

activity实现

import android.annotation.SuppressLint

import android.graphics.BitmapFactory

import android.os.Bundle

import androidx.appcompat.app.AppCompatActivity

import com.bumptech.glide.Glide

import com.bumptech.glide.request.target.SimpleTarget

import com.bumptech.glide.request.transition.Transition

import kotlinx.android.synthetic.main.activity_glide_view.*

import java.io.File

/**

*@Created by wrs on 2020/11/7,15:46

*@packageName: com.dsy.tui

*@Description: 图片加载

*/

class GlideImageActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_glide_view)

val imgPath = "https://yd-imgs.380star.com/upload/uploadfile/2020/4/23/158763676174928364815980349689.jpg"

Glide.with(this).load(imgPath)

.downloadOnly(object : SimpleTarget() {

override fun onResourceReady(resource: File, transition: Transition?) {

// 将保存的图片地址给SubsamplingScaleImageView,这里注意设置ImageViewState设置初始显示比例

val bitmap =

BitmapFactory.decodeFile(resource.getAbsolutePath(), getBitmapOption(1))

// 显示处理好的Bitmap图片

ivImg.setImageBitmap(bitmap)

}

})

}

/**

* 设置Bitmap的Options

*/

private fun getBitmapOption(inSampleSize: Int): BitmapFactory.Options? {

System.gc()

val options = BitmapFactory.Options()

options.inPurgeable = true

options.inSampleSize = inSampleSize

return options

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值