CustomView in Kotlin @ potatotips #42

CustomView in Kotlin @ potatotips #42

potatotips #42にて発表したKotlinでCustomViewを作る話のスライドです。

0f50b010cc99988fba8a73008b21f353?s=128

Yoshihiro WADA

July 25, 2017
Tweet

Transcript

  1. $VTUPN7JFXJO,PUMJO :PTIJIJSP8BEBBLB!FEPLVQ QPUBUPUJQT!$PPLQBE *OD

  2. ୭΍ͶΜ͓લ  :PTIJIJSP8BEB Ɠ $ZCFS"HFOU *OD  "EUFDI4UVEJP"*.FTTFOHFS !FEPLVQ ȍ

    FEPLVQ FEPLVQ ,PUMJO ྺ  ϲ݄
  3. ,PUMJO ྺ  ϲ݄ ୭΍ͶΜ͓લ  :PTIJIJSP8BEB Ɠ $ZCFS"HFOU *OD

     "EUFDI4UVEJP"*.FTTFOHFS !FEPLVQ ȍ FEPLVQ FEPLVQ
  4. ࠓճ࿩͢͜ͱ  ⋆ ,PUMJO Ͱ $VTUPN7JFX Λ࡞੒͢Δ ? ίϯετϥΫλ͸Ͳ͏ͳΔʜʁ ?

    +BWB ͔ΒݺͿࡍʹ͸ʜʁ ? $BMMCBDL ͸Ͳ͏͢Ε͹ʜʁ
  5. $POTUSVDUPS  QVCMJDDMBTT$VTUPN7JFXFYUFOET7JFX\ QVCMJD$VTUPN7JFX $POUFYUDPOUFYU \ TVQFS DPOUFYU  JOJU

    ^ QVCMJD$VTUPN7JFX $POUFYUDPOUFYU !/VMMBCMF"UUSJCVUF4FUBUUST \ TVQFS DPOUFYU BUUST  JOJU ^ QVCMJD$VTUPN7JFX $POUFYUDPOUFYU !/VMMBCMF"UUSJCVUF4FUBUUST      JOUEFG4UZMF"UUS \ TVQFS DPOUFYU BUUST EFG4UZMF"UUS  JOJU ^ QSJWBUFWPJEJOJU \ JOJUJBMJ[F ^ NFUIPET ^ ⋆ ී௨ͷ $POTUSVDUPS
  6. $POTUSVDUPS  DMBTT$VTUPN7JFX7JFX\ DPOTUSVDUPS DPOUFYU$POUFYU TVQFS DPOUFYU DPOTUSVD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࣌͠ͷҾ਺໊͕ʜ +BWB ӘӒҷӲӴ㗾ӕӔӍӉǘ㮹
  17. $BMMCBDL ʹ͍ͭͯࢥ͏͜ͱ  ⋆ ؔ਺ϦςϥϧͰϦεφʔύλʔϯഉআ͸Ͱ͖Δ ⋆ ϦεφʔύλʔϯΛ࢖ͬͨ΄͏͕ϝϯςφϯε ͠΍͍͢έʔε͸͍ͬͺ͍͋Γͦ͏ ෳ਺ͷҾ਺͕ଘࡏ͢Δͱ͖ ଟ਺ͷίʔϧόοΫؔ਺Λ࣋ͭͱ͖

    ⋆ ٯʹར༻ͨ͠ํ͕ྑͦ͞͏ͳέʔε΋͋Γͦ͏ ඞͣఆٛ͢Δඞཁͷͳ͍ίʔϧόοΫ͕͋Δ࣌ FH(FTUVSF%FUFDUPS(FTUVSF-JTUFOFS ͷ಺  μϒϧλοϓͷݕ஌͚ͩར༻͍ͨ͠ɺͱ͔
  18. ࢀߟจݙ  ⋆ +BWB ͔Βͷར༻Λࢹ໺ʹೖΕͨ ,PUMJO ίʔυͰ ԿΛ͢Δ΂͖͔2JJUB IUUQRJJUBDPNKNBUTVJUFNTDCBBDCDCG ⋆

    +BWB,PUMJO ࠞ߹ϓϩδΣΫτͰؾΛ͚͍ͭͯΔ͜ͱɻ IUUQMWMBIBUFOBCMPHDPNFOUSZ ⋆ ,PUMJO ͰίʔϧόοΫ2JJUB IUUQRJJUBDPN""LJSB!HJUIVCJUFNTFCBBFFECED