Without layout parameters, there is not much we can do with our layouts. In this recipe, we will see how to use layout parameters with views in our layout DSL.
I'll be using Android Studio 3 to write code. You can get started by creating a new project in Kotlin with a blank activity in Android Studio 3+, as we won't be using any code from other recipes. You also need an intermediate understanding of Android development. Ensure that you have added Anko layouts dependencies to your project (follow the recipe Setting up Anko library for Anko layouts in gradle, in this chapter).
In the following steps, we will learn how to set the layout parameters for Anko views:
- Let's start with creating our view in an external class that inherits from the
AnkoComponent
interface. To add layout parameters to a view (which we add using the extension functions provided by Anko), we use thelparams()
extension function, which we add at the end of...