Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RecyclerViewで 折れ線グラフを作る

B8f695167d115eef9f32399b1c9261df?s=47 Yuki Mima
December 12, 2019

RecyclerViewで 折れ線グラフを作る

B8f695167d115eef9f32399b1c9261df?s=128

Yuki Mima

December 12, 2019
Tweet

Transcript

  1. 3FDZDMFS7JFXͰ ંΕઢάϥϑΛ࡞Δ %.."OESPJEษڧձ !BNZV@TBO

  2. "CPVUNF w 5XJUUFS!BNZV@TBO w HJUIVCBNZV w 1JDBQQJOD w 5FMMFS

  3. "HFOEB w ࡞Γ࢝ΊΔલஔ͖ w ࡞ͬͯΈͨ w ϝϦοτŊσϝϦοτ w ·ͱΊ

  4. άϥϑͱݴͬͯࢥ͍ͭ ͘ͷ͕

  5. None
  6. .1"OESPJE$IBSU

  7. ͘͢͝ྑ͘Ͱ͖ͨ-JCSBSZ Ͱେม͓ੈ࿩ʹͳͬͯ·͢

  8. ͨͩŊ࣌ʑσβΠϯ௨ ΓʹͳΒͳ͍͕࣌͋Δ

  9. w σβΠφ͞Μʹ.1"OESPJE$IBSUͰͰ͖Δൣғ಺Ͱσβ ΠϯΛม͑ͯ΋Β͏ w σβΠφ͞Μͷظ଴ʹͨ͑͜ΕΔΑ͏ؤுͬͯ࡞Δ

  10. w σβΠφ͞Μʹ.1"OESPJE$IBSUͰͰ͖Δൣғ಺Ͱσβ ΠϯΛม͑ͯ΋Β͏ w σβΠφ͞Μͷظ଴ʹͨ͑͜ΕΔΑ͏ؤுͬͯ࡞Δ

  11. "HFOEB w ࡞Γ࢝ΊΔલஔ͖ w ࡞ͬͯΈͨ w ϝϦοτŊσϝϦοτ w ·ͱΊ

  12. None
  13. w "EBQUFSͭ w *UFN%FDPSBUJPOͭ

  14. None
  15. "EBQUFS

  16. 7JFX)PMEFS

  17. None
  18.  

  19.  

  20. Y ZDBOWBTIFJHIU TUBSU:  YDBOWBTXJEUI ZDBOWBTIFJHIU FOE: 

  21. None
  22. *UFN%FDPSBUJPO

  23. abstract class HorizontalDateItemDecoration( private val _context: Context ) : RecyclerView.ItemDecoration(),

    ViewExtensions { private val height = 64.dp private val textSize = 14f.sp private val backgroundPaint = Paint().apply { color = Color.parseColor("#000000") } private val dayTextPaint = Paint().apply { color = Color.parseColor("#FF00FF") textSize = this@HorizontalDateItemDecoration.textSize isAntiAlias = true } private val yearAndMonthPaint = Paint().apply { color = Color.parseColor("#FFFF00") textSize = this@HorizontalDateItemDecoration.textSize isAntiAlias = true } override fun getContext(): Context = _context override fun onDraw( canvas: Canvas, parent: RecyclerView, state: RecyclerView.State ) { canvas.drawRect(0f, 0f, canvas.width.toFloat(), height.toFloat(), backgroundPaint) var isVisibleFirstDay = false var isVisibleLastDay = false var lastVisibleYearAndMonthText = "" var lastVisibleYearAndMonthY = 0f parent.children.forEach { view -> val adapterPosition = parent.getChildAdapterPosition(view) val localDateFromPosition = getDate(adapterPosition) //೔෇ͷඳը val dayText = localDateFromPosition.dayOfMonth.toString() val dayTextSizeRect = getTextSizeRect(dayTextPaint, dayText) val dayTextX = view.x + (view.width - dayTextSizeRect.width()) / 2 val dayTextY = dayTextSizeRect.height().toFloat() + (height / 2 - dayTextSizeRect.height()) / 2 + height / 2 canvas.drawText(dayText, dayTextX, dayTextY, dayTextPaint) //೥݄ͷඳը val yearAndMonthText = "${localDateFromPosition.year}೥${localDateFromPosition.monthValue}݄" val yearAndMonthTextSizeRect = getTextSizeRect(yearAndMonthPaint, yearAndMonthText) val yearAndMonthY = yearAndMonthTextSizeRect.height().toFloat() + (height / 2 - yearAndMonthTextSizeRect.height()) / 2 val isFirstDayOfMonth = localDateFromPosition.isEqual(localDateFromPosition.with(firstDayOfMonth())) val isLastDayOfMonth = localDateFromPosition.isEqual(localDateFromPosition.with(lastDayOfMonth())) when { isFirstDayOfMonth -> { (view.x).let { x -> if (x > 0) { canvas.drawText(yearAndMonthText, x, yearAndMonthY, yearAndMonthPaint) } else { canvas.drawText(yearAndMonthText, 0f, yearAndMonthY, yearAndMonthPaint) } } isVisibleFirstDay = true } isLastDayOfMonth -> { (view.x + view.width - yearAndMonthTextSizeRect.width()).let { x -> if (x < 0) { canvas.drawText(yearAndMonthText, x, yearAndMonthY, yearAndMonthPaint) } else { canvas.drawText(yearAndMonthText, 0f, yearAndMonthY, yearAndMonthPaint) } } isVisibleLastDay = true } } lastVisibleYearAndMonthText = yearAndMonthText lastVisibleYearAndMonthY = yearAndMonthY } //೥݄ͷඳը if (!isVisibleFirstDay && !isVisibleLastDay) { canvas.drawText( lastVisibleYearAndMonthText, 0f, lastVisibleYearAndMonthY, yearAndMonthPaint ) } } override fun getItemOffsets( outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State ) { outRect.set(0, height, 0, 0) } abstract fun getDate(position: Int): LocalDate }
  24. None
  25. EQ

  26. w "EBQUFS΍7JFX)PMEFS͕໨੝ΓΛඳը͢ΔྖҬͷ͜ͱΛ ߟ͑ͳͯ͘͢Ή

  27. None
  28. "HFOEB w ࡞Γ࢝ΊΔલஔ͖ w ࡞ͬͯΈͨ w ϝϦοτŊσϝϦοτ w ·ͱΊ

  29. ϝϦοτ w खͷಧ͘ൣғ಺Ͱϝϯςφϯε͕Ͱ͖Δ w σβΠϯͷमਖ਼͕͠΍͍͢ w ੹຿Λ෼͚Δ͜ͱ͕Ͱ͖Δ w "EBQUFSͱ7JFX)PMEFSΛάϥϑ෦෼ w

    *UFN%FDPSBUJPOΛॎ࣠Ŋԣ࣠ͷ໨੝ w *UFNͷ$MJDL&WFOUΛϋϯυϦϯά͢Δͷ΋ָ w $BOWBTͰ4DSPMMBCMFͳάϥϑΛ࡞Δͷ͸େม͚ͩͲŊ͜ΕͳΒ؆୯ͩͶ
  30. σϝϦοτ w ΍ͬͺΓ࣌ʑݶք͕͋Δ w $BOWBTͰؤுΖ͏

  31. "HFOEB w ࡞Γ࢝ΊΔલஔ͖ w ࡞ͬͯΈͨ w ϝϦοτŊσϝϦοτ w ·ͱΊ

  32. ·ͱΊ w 3FDZDMFS7JFX͸ແݶͷՄೳੑΛײ͡Δ w -BZPVU.BOBHFS࢖͑͹ԁάϥϑ΋Ͱ͖Δ w 3FDZDMFS7JFXΛ4DSPMMͷύϑΥʔϚϯε͕ྑ͘ͳΔΧε λϜ7JFX(SPVQͱͯ͠࢖͍ͬͯ͘ͷ͸ྑ͍બ୒

  33. https://github.com/amyu/HorizontalDateItemDecoration/

  34. ͝ਗ਼ௌ͋Γ͕ͱ͏͟͝ ͍·ͨ͠