Updated 6 September 2019
Anko is a Kotlin library which is development by the kotlin team which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.
XML Layouts are parsed at runtime. In other the XML needs to be retrieved form the assets, and the XmlPullParser needs to parse all the elements and create them one by one.
Lets take a look how anko make your android application development faster and easier.
View.setOnClickListener method is used everywhere in Android projects so it would be nice if we could make it more concise.
1 2 3 4 |
button.setOnClickListener(object : View.OnClickListener{ override fun onClick(view: View) { } }) |
But Anko helps to minimize the effort we have to make:
1 |
button.onClick { } |
Using intents is one of the first things you will learn as an Android developer, but the API could be more convenient.
1 2 3 4 |
val intent = Intent(this, MainActivity::class.java) intent.putExtra("id", 5) intent.putExtra("name", "John") startActivity(intent) |
Let’s see how could it be more simple:
1 |
startActivity<mainactivity>("id" to 5, "name" to "John") |
Defining the layout in anko is much easier than the traditional xml layout
1 2 3 4 5 6 7 8 9 10 11 12 13 |
verticalLayout { padding = dip(16) textView("Username:") { textSize = 18f }.layoutParams { verticalMargin = dip(4) } val login = editText() button("Sign up") { textSize = 20f onClick { login(login.text) } }.layoutParams { topMargin = dip(8) } } |
Anko is not just about to minimize the code but it also 300% faster performance comparisonĀ than the traditional xml layout.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.