Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adavis
Last active December 16, 2017 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adavis/ca1fbbd0534230d10a655f172705f188 to your computer and use it in GitHub Desktop.
Save adavis/ca1fbbd0534230d10a655f172705f188 to your computer and use it in GitHub Desktop.
Implementation of the createView method for a Sample Anko Component
override fun createView(ui: AnkoContext<PlanetDetailFragment>): View {
return with(ui) {
val container = verticalLayout {
lparams(matchParent)
textView {
setLineSpacing(8f, 1f)
}.lparams {
topMargin = dip(16)
}
textView {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_landscape, 0, 0, 0)
}
textView {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_brightness, 0, 0, 0)
}
textView {
setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_loop, 0, 0, 0)
}
}
container.applyRecursively { view ->
when (view) {
is TextView -> {
with(view) {
padding = dip(16)
compoundDrawablePadding = dip(16)
layoutParams.width = matchParent
setTextIsSelectable(true)
textAppearance = R.style.TextAppearance_AppCompat_Medium
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment