본문 바로가기

IT/Android101

Kotlin] 안드로이드 레이아웃을 이미지로 변환하기 레이아웃을 비트맵으로 변환합니다 뷰를 비트맵으로 변환하는 코드로 사용했는데 됐습니다; // 뷰를 비트맵으로 변환 fun viewToBitmap(view: View): Bitmap { val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) view.draw(canvas) return bitmap } viewToBitmap(frameLayout) [안드로이드 예제] Bitmap 이용해서 이미지 파일 원하는 크기로 자르기/늘리기(사진확대,축소) Bitmap 요즘 주말마다 한창 안드로이드 어플을하나 만들고 있습니다.저번 게시물에 관련 내용을 살짝 올렸... blog.na.. 2021. 3. 20.
Kotlin] 안드로이드 뷰 확대하기, 늘리기 // Pinch zoom 뷰를 확대해봅시다 손가락으로 늘리고 줄이고~ private var scaleGestureDetector: ScaleGestureDetector? = null private var scaleFactor = 1.0f .... override fun onTouchEvent(event: MotionEvent?): Boolean { scaleGestureDetector?.onTouchEvent(event) return true } inner class ScaleListener : SimpleOnScaleGestureListener() { override fun onScale(scaleGestureDetector: ScaleGestureDetector): Boolean { scaleFactor *= scaleGes.. 2021. 3. 18.
Kotlin] 안드로이드 뷰 눌러서 이동하기n] 안드로이드 뷰 눌러서 이동하기 // view MotionEvent 뷰를 눌러서 이동해보겠습니다 예제는 리사이클러뷰지만 아무 뷰나 상관없습니다. #이미지 뷰 #텍스트뷰 #리사이클러뷰 #리스트뷰 var startX = 0f var startY = 0f ... recyclerView.setOnTouchListener { v, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { startX = event.x startY = event.y } MotionEvent.ACTION_MOVE -> { val movedX: Float = event.x - startX val movedY: Float = event.y - startY v.x = v.x + movedX v.y = v.y + movedY } } true } 처음 눌렀을 .. 2021. 3. 18.
Kotlin] Custom 모델로 정의된 배열 저장하기 // sharedPreference ListViewItem으로 정의된 리스트뷰 아이템 배열을 저장하는 SharedPreferences 함수 만들기 1. gradle에 gson 추가해주고 implementation 'com.google.code.gson:gson:2.8.5' google/gson A Java serialization/deserialization library to convert Java Objects into JSON and back - google/gson github.com 2. 값 저장하는 함수 fun setStringArrayPref(key: String, values: ArrayList) { val gson = Gson() val json = gson.toJson(values) val prefs = getShared.. 2021. 3. 15.