Kotlin return value

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.