Return and = Flexible application
Example 1
Fun sum (a:int,b:int): int{
return a+b
}
Fun sum (a:int,b:int) = a + b
Example 2
Fun Max (A:int, b:int): Int {
if (a > B)
return a
else
return b
}
Fun Max (a:int, b:int) = if (a > B) a else B
Example 3
Fun Initui (): linearlayout {
return verticallayout {
button {
text = "One"
}
TextView {
Text = "}.lparams"
{
width = matchparent
gravity = gravity.center_horizontal
}
}}
Fun Initui () = verticallayout {
button {
text = "One"
}
textView {
text = "One"
}.lparams {
W Idth = matchparent
gravity = Gravity.center_horizontal
}
}
The interface effect of example two implementation
Note:
1. When writing a layout file with Anko, write the Layoutparams property of the control after Lparams. If you specify Lparams (), but omit width or height, their default values are wrap_content.
2, Layoutparams it encapsulates layout (layout) position, height, width and other information, location information is whether the center, left and right margin and so on.