일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 명언모음
- 좋은글필사하기
- 장자명언
- androidx
- 코틀린
- Flutter
- 공부집중
- bash
- recyclerview
- Streaming
- 1인개발자
- 이모지
- 벤자민플랭클린
- kotlin
- ASMR
- 넷플릭스
- FSM
- DART
- 이모지메모
- Linux
- 오픈소스
- jetpack compose
- 공자명언
- Coroutine
- Firebase
- 소울칼리버6
- Android
- 파이썬
- Freesound
- 명심보감
Archives
- Today
- Total
Vintage appMaker의 Tech Blog
[kotlin] RecyclerView full size capture - 코틀린 변환 본문
Source code or Tip/Android(Java, Kotlin)
[kotlin] RecyclerView full size capture - 코틀린 변환
VintageappMaker 2020. 8. 16. 17:02원본링크
https://stackoverflow.com/questions/30085063/take-a-screenshot-of-recyclerview-in-full-length
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.view.View
import androidx.collection.LruCache
import androidx.recyclerview.widget.RecyclerView
fun getScreenshotFromRecyclerView(view: RecyclerView): Bitmap? {
val adapter = view.adapter
var bigBitmap: Bitmap? = null
if (adapter != null) {
val size = adapter.itemCount
var height = 0
val paint = Paint()
var iHeight = 0
val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt()
// Use 1/8th of the available memory for this memory cache.
val cacheSize = maxMemory / 8
val bitmaCache =
LruCache<String, Bitmap>(cacheSize)
for (i in 0 until size) {
val holder =
adapter.createViewHolder(view, adapter.getItemViewType(i))
adapter.onBindViewHolder(holder, i)
holder.itemView.measure(
View.MeasureSpec.makeMeasureSpec(
view.width,
View.MeasureSpec.EXACTLY
),
View.MeasureSpec.makeMeasureSpec(
0,
View.MeasureSpec.UNSPECIFIED
)
)
holder.itemView.layout(
0,
0,
holder.itemView.measuredWidth,
holder.itemView.measuredHeight
)
holder.itemView.isDrawingCacheEnabled = true
holder.itemView.buildDrawingCache()
val drawingCache = holder.itemView.drawingCache
if (drawingCache != null) {
bitmaCache.put(i.toString(), drawingCache)
}
// holder.itemView.setDrawingCacheEnabled(false);
// holder.itemView.destroyDrawingCache();
height += holder.itemView.measuredHeight
}
bigBitmap =
Bitmap.createBitmap(view.measuredWidth, height, Bitmap.Config.ARGB_8888)
val bigCanvas = Canvas(bigBitmap)
bigCanvas.drawColor(Color.WHITE)
for (i in 0 until size) {
val bitmap = bitmaCache[i.toString()]
bigCanvas.drawBitmap(bitmap!!, 0f, iHeight.toFloat(), paint)
iHeight += bitmap.height
bitmap.recycle()
}
}
return bigBitmap
}
'Source code or Tip > Android(Java, Kotlin)' 카테고리의 다른 글
[Android] 커스텀 폰트 사용시, 강제로 TextView의 패딩이 들어가는 현상 (0) | 2020.12.14 |
---|---|
ADB를 이용한 Android와 PC 통신 (0) | 2020.12.13 |
[Link] Android Bitmap에 워터마크 추가하기 (0) | 2020.08.12 |
Android Toast 중복방지 (0) | 2020.08.10 |
[Android] appBook source (0) | 2020.07.20 |
Comments