Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ankoで触れるKotlin
Search
Yoshida Seisuke
July 05, 2017
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ankoで触れるKotlin
Yoshida Seisuke
July 05, 2017
Other Decks in Programming
See All in Programming
カツオ、ご期待ください
suneo3476
0
190
すこし踏み込む CancellationToken
htkym
2
1.7k
AWSに止められる覚悟してますか?
morizo_1984
2
540
Workers Cache を知る
syumai
0
360
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
220
Jetpack Compose Mechanisms
skydoves
3
820
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
460
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Building Flexible Design Systems
yeseniaperezcruz
330
41k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
So, you think you're a good person
axbom
PRO
2
2.2k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
The agentic SEO stack - context over prompts
schlessera
0
970
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
Transcript
Anko Ͱ৮ΕΔKotlin 2017.07.05 Fukuoka.kt #1
ࣗݾհ • ٢ాਗ਼྄ (twitter|github).com/seisuke • ݱࡏ੍࡞ͷΞϓϦͰ100%Kotlin Version1.1.x →ৄࡉ7/19ͷLINE Developer Meetup
in Fukuoka #18Ͱ
• Ankoͱ • ͳͥAnko͍͍ͷʁ • Tips ΞδΣϯμ
• Anko Layoutsͱ͍͏ViewΛ࡞ΔҝDSLͷϥΠϒϥϦ →XMLΛΘͳͯ͘ྑ͍ɻ௨ৗAnkoComponentͷαϒΫϥεΛ࡞Δ • https://github.com/Kotlin/anko 0.10.1 • https://twitter.com/yanex_ru https://github.com/yanex
• dex.fm #17 #18 ޠݯᰩࢠ(Android + Kotlin) Ankoͱ
• Data Binding͑·ͤΜ • ConstraintLayoutະରԠ • UI Previewɺ”ࠓ”ಈ͔ͳ͍ ࠷ॳʹAnkoͷ൵͍͠ͱ͜Ζ
• ͍ → XML͕͍ • Anko Layouts DSL Ͱ Type
Safety • CustomView ͳͥAnko͍͍ͷʁ
relativeLayout { lparams(width = matchParent, height = dimen(R.dimen.action_bar_size)) leftButton =
ankoView(::ToolbarButton, 0) { id = generateViewId() toolbarType =
[email protected]
}.lparams(height = matchParent) { centerVertically() } rightButton = customView<ToolbarButton> { id = generateViewId() }.lparams(height = matchParent) { alignParentRight() centerVertically() } centerLayout = linearLayout { gravity = Gravity.CENTER }.lparams(width = matchParent) { rightOf(leftButton) leftOf(rightButton) centerInParent() } } Anko Layouts DSL
• Ҿ࠷ޙͷLambdaʢϨγʔόࢦఆʣ • Extensions • @DslMarker →AnkoDSLΛ࡞Δ࣌ͷ͍͍͓खຊʹͳΔ Kotlin ❤ DSL
• ࡞Δͷ؆୯ɺ ViewΛܧঝͯ͠ constructorʹContextΛ͚࣋ͭͩ • ͏ͷ؆୯ val button = customView<ToolbarButton>
{ … } val button = ankoView(::ToolbarButton, 0) { … } • Define Custom Attributes ͍Ͱ͠ΐʁ https:// developer.android.com/training/custom-views/create-view.html Custom View
Custom View inline fun <T : View> ViewManager.ankoView(factory: (ctx: Context)
-> T, theme: Int, init: T.() -> Unit): T { val ctx = AnkoInternals.wrapContextIfNeeded(AnkoInternals.getContext(this), theme) val view = factory(ctx) view.init() AnkoInternals.addView(this, view) return view } inline fun <reified T : View> ViewManager.customView(theme: Int = 0, init: T.() -> Unit): T { return ankoView({ ctx -> AnkoInternals.initiateView(ctx, T::class.java) }, theme) { init() } }
• ؾָʹCustom View͕͑Δ → Type SafetyʹͳΔ → findById͕͍Βͳ͍ Custom View
Custom View class UserListAdapter : BaseAdapter<User>() { override fun
onBindBasicItemView(holder: RecyclerView.ViewHolder, position: Int) { if (holder is UserViewHolder) { holder.bind(getBaseItem(position)) } } override fun onCreateBasicItemViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return UserViewHolder(holderView(parent)) } fun holderView(parent: ViewGroup): UserView = with(AnkoContext.create(parent.context, parent)) { customView { textView = textView { … } } } class UserView(ctx: Context) : _LinearLayout(ctx) { lateinit var textView: TextView } inner class UserViewHolder(val view: UserView) : RecyclerView.ViewHolder(view) { fun bind(user: User) { view.textView.text = user.name } } }
• DelegationͰڞ௨ػೳ → ωοτϫʔΫॲཧͱ͔ • RelativeLayout • OnGlobalLayout Tips
• AnkoId࡞Δͷ͕େมʁ @+id/ • generateViewId͕͋ΔΑ fun View.generateViewId(): Int { return
if (Build.VERSION.SDK_INT >= 17) { View.generateViewId() } else { this.hashCode() } } RelativeLayout
fun <T : View > T.onGlobalLayoutAction(once: Boolean = true, action:
T.() -> Unit) { viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { action() if (once) { this@onGlobalLayoutAction .viewTreeObserver.removeOnGlobalLayoutListener(this) } } }) } OnGlobalLayout
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠