Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ScrollViewで 読了計測した話
Search
ogapants
December 11, 2018
Technology
0
790
ScrollViewで 読了計測した話
2018/12/11 Otemachi.apk
ogapants
December 11, 2018
Tweet
Share
More Decks by ogapants
See All by ogapants
5分でわかるWebView+ViewGroupを実現するAOSPメールアプリの内部実装と ニュースアプリへの応用 / Otemachi.apk02
ogapants
0
690
WebView+ViewGroupを実現するAOSPメールアプリの内部実装とニュースアプリへの応用 / DroidKaigi2019
ogapants
3
3.4k
「AndroidはiOSと同じデザインで!」と言われたときのTips
ogapants
18
8.4k
たのしいAndroidかいはつ
ogapants
0
150
Fabric Digitsで始めるSMS認証
ogapants
1
1.2k
MediaController をカスタマイズするぞ
ogapants
0
2.7k
Other Decks in Technology
See All in Technology
三菱電機で社内コミュニティを立ち上げた話
kurebayashi
1
360
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
embedパッケージを深掘りする / Deep Dive into embed Package in Go
task4233
1
220
2025年に挑戦したいこと
molmolken
0
160
「隙間家具OSS」に至る道/Fujiwara Tech Conference 2025
fujiwara3
7
6.5k
AWS Community Builderのススメ - みんなもCommunity Builderに応募しよう! -
smt7174
0
180
KMP with Crashlytics
sansantech
PRO
0
240
My small contributions - Fujiwara Tech Conference 2025
ijin
0
1.4k
AWSマルチアカウント統制環境のすゝめ / 20250115 Mitsutoshi Matsuo
shift_evolve
0
120
Evolving Architecture
rainerhahnekamp
3
260
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
450
GoogleのAIエージェント論 Authors: Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic
customercloud
PRO
0
160
Featured
See All Featured
Site-Speed That Sticks
csswizardry
3
270
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
113
50k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
870
GitHub's CSS Performance
jonrohan
1030
460k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
Code Reviewing Like a Champion
maltzj
521
39k
Transcript
ScrollViewͰ ಡྃܭଌͨ͠ 2018/12/11 Otemachi.apk @ogapants
ࣗݾհ • ͓͕ͺΜ@ogapants • ೖࣾ • ٕज़ॻయͰνʔϜվળͱ AndroidStudioͷTipsʹ͍ͭͯॻ͍ͨ noteͰങ͑ΔΑʂ https://goo.gl/AWv7v1
ScrollViewͰ ಡྃܭଌͨ͠
ʮಡྃʯͱ • શͯಡΈऴ͑Δ͜ͱ • ΞϓϦͰ͍͏ͱը໘ͷҙͷॴ·ͰεΫ ϩʔϧ͠ऴΘΔ͜ͱ
ฐࣾʹ͓͚Δಡྃܭଌͱ • ୭͕ • ͲͷهࣄΛ • Ͳ͔͜Β • Ͳ͜·Ͱ •
ͲΕ͘Β͍ͷ࣌ؒͰ • ಡΜ͔ͩʢεΫϩʔϧ͔ͨ͠ʣ Λܭଌͯ͠αʔόʔʹૹΓɺσʔλνʔϜ͕ੳ
ಡྃܭଌͱ • ༨ஊɿૹΓઌࣾͷܭଌج൫ʮAtlasʯ
ԿΛͨ͠ͷ͔
ͳͥͨ͠ͷ͔ • ϢʔβʔʹΑΓଟ͘هࣄΛಡΜͰ΄͍͠ ˠBը໘Λ࡞Γ͍ͨ ˠطଘͷAը໘ͱൺͯͲ͏͔ςετ͍ͨ͠ ˠPV͚ͩͩͱਅ৽͠͞ͰݟΒΕ͍ͯΔՄೳੑ ˠܧଓతʹڵຯΛ࣋ͬͯಡΜͰ͍Δ͔Γ͍ͨ ˠΑΓϢʔβʔͷߦಈΛৄ͘͠ܭଌ͢Δඞཁ͕ ͋Δ
ԿΛͨ͠ͷ͔ • Aը໘ͱBը໘Ͱಡྃʹ͕ࠩແ͍͔ܭଌ Aը໘ Bը໘
Ͳ͏ͩͬͨͷ͔ • ݁ՌɺBը໘ظҎ্ͷಡ͕ྃ͞Εͨ • Bը໘ͷ༗༻ੑΛࣈతࠜڌΛ ࣋ͬͯΞϐʔϧͰ͖ͨ • ۙϦϦʔε༧ఆʂ
ΞϓϦهࣄը໘ͷߏ
هࣄը໘ͷߏ ϔομʔ ʢλΠτϧͳͲʣ ίϯςϯπ (WebView) ϑολʔ ʢؔ࿈هࣄҰཡͳͲʣ ʢಡྃʹؚ·ͳ͍ʣ ScrollView Ad
هࣄը໘ͷߏ device ViewPagerͰ εϫΠϓՄೳ
ܭଌ͢Δͷ
ܭଌ͢Δͷ • ૹΔ • ૹΔλΠϛϯά
ૹΔ • هࣄ͕ඇදࣔʹͳΔ·Ͱͷ࣌ؒ(ms)ɹˠ؆୯ͳλΠϚʔΫϥεΛ ࡞ͬͨ • هࣄશମͷ͞(px)ɹˠಡྃͷॏ͞ΛΔͨΊ • هࣄදࣔ࣌ͷઌ಄(px)ɹˠ࠷ॳ͔ΒಡΈ࢝Ίͨͷ్͔த͔Βͳ ͷ͔ΔͨΊ(ޙड़) •
هࣄඇදࣔ࣌ͷඌ(px)ɹˠͲ͜·ͰಡΜͩͷ͔ΔͨΊ(ޙड़) • ಡྃ(%)ɹˠඌ/શମͷ͞
ૹΔλΠϛϯά • ը໘͕ݟ͑Δঢ়ଶ͔Βݟ͑ͳ͍ঢ়ଶʹͳͬͨ ͱ͖ • onPause࣌ or ViewPagerͷඇselect࣌Ͱ ૹΔ
Ͳ͏࣮͢Δͷ͔
ૹΔ • هࣄ͕ඇදࣔʹͳΔ·Ͱͷ࣌ؒɹˠ؆୯ͳλΠϚʔΫϥεΛ࡞ͬ ͨ • هࣄશମͷ͞ɹˠಡྃͷॏ͞ΛΔͨΊ • هࣄදࣔ࣌ͷઌ಄ɹˠ࠷ॳ͔ΒಡΈ࢝Ίͨͷ్͔த͔Βͳ ͷ͔ΔͨΊ(ޙड़) •
هࣄඇදࣔ࣌ͷඌɹˠͲ͜·ͰಡΜͩͷ͔ΔͨΊ(ޙड़) • ಡྃɹˠඌ/શମͷ͞ →View#getLocationInWindow →View#getLocalVisibleRect
Ͳ͏࣮͢Δͷ͔ • ઌ಄…View#getLocationInWindow • ඌ…View#getLocalVisibleRect • View#getScrollY →ಈతʹߴ͞ͷมΘΔϑολʔಡྃʹؚΊͳ͍ͨΊɺ ͑ͦ͏Ͱ͑ͳ͍
εΫϩʔϧྔͰͳ͘εΫϩʔϧ͞ΕͨViewͷҐஔͰஅ
View#getLocationInWindow • window্ͷViewͷࠨ্ͷ࠲ඪ(x,y)ΛྻͰऔಘ • ϔομʔΛͲ͜·Ͱ্ʹεΫϩʔϧ͔͕ͨ͠औΕΔ • yͰઌ಄Λऔಘ • val arr
= IntArray(2) view.getLocationInWindow(arr) val y = arr[1]
View#getLocationInWindow • ͍͍ͩͨͷ(x,y) (0,300) (0,1500) (0,-300) 1000x2000 ͷը໘ View x
y
View#getLocalVisibleRect • ViewͷՄࢹྖҬͷۣܗ(Rect)Λऔಘʢͪΐͬͱಛघʣ • ίϯςϯπ͕ͲΕ͘Β͍εΫϩʔϧ͞Ε͍ͯΔ͔औΕΔ • bottomͰඌΛऔಘ • val rect
= Rect() view.getLocalVisibleRect(rect) val position = rect.bottom
• ͍͍ͩͨͷ(left,top,right,bottom) View#getLocalVisibleRect (0,0,1000,400) (0,0,1000,400) (0,0,1000,200) (0,50,1000,2450) 1000x2000 ͷը໘ View
- - - - - - - - - - -
• ͍͍ͩͨͷ(left,top,right,bottom) View#getLocalVisibleRect (0,0,1000,400) (0,0,1000,400) (0,200,1000,400) (0,-450,1000,-50) 1000x2000 ͷը໘ View
- - - - - - - - - - -
εΫϩʔϧͷύλʔϯ
εΫϩʔϧঢ়ଶͷύλʔϯग़͠
ॳظঢ়ଶ
εΫϩʔϧঢ়ଶ1
εΫϩʔϧঢ়ଶ2
εΫϩʔϧঢ়ଶ3
εΫϩʔϧঢ়ଶ4
εΫϩʔϧঢ়ଶͷύλʔϯग़͠ • Ұݟ໘͚ͩͲެࣜΛग़ͤ؆୯
͍͞͝ʹ
FAQ • ͍ͯ͏͔ScrollViewʹWebViewೖΕ͍͍ͯͷʁ ˠͩΊͰ͢ɻby googler • ͡Ό͋͜ͷͲ͏ͳΔͷʁ ˠઈࢍॻ͖͑தͳͷͰࠓճڙཆ͞Ε·ͨ͠ • WebViewͱViewGroupΛΈ߹Θ͍ͤͨͱ͖ScrollView
Ͱғ͏Ҏ֎ରԠҊ͋Δͷʁ ˠ
DroidKaigi2019 ʮWebView+ViewGroupΛ࣮ݱ͢ΔAOSPϝʔϧ ɹΞϓϦͷ෦࣮ͱχϡʔεΞϓϦͷԠ༻ʯ ͱ͍͏λΠτϧͰ͢Αʂ
·ͱΊ • ฐ͍ࣾΖ͍Ζੳͯࠜ͠ڌ͋ΔࣈΛݩʹվ ળͯ͠ΔΑ • Viewͷදࣔঢ়ଶΛݟΔʹ getLocationInWindowgetLocalVisibleRectΛ ͏ͱ͍͍Α • ScrollViewʹWebViewೖΕͪΌବͩΑ