Layout DSL Save

Build Android layout dynamically with kotlin, get rid of xml file, which has poor performance

Project README

Layout_DSL

Build Android layout dynamically with kotlin, get rid of xml file, which has poor performance

class MainActivity : AppCompatActivity() {
    // build layout dynamically by DSL
    private val contentView by lazy {
        ConstraintLayout {
            layout_width = match_parent
            layout_height = match_parent

            TextView {
                layout_width = wrap_content
                layout_height = wrap_content
                text = "commit"
                textSize = 30f
                gravity = gravity_center
                center_horizontal = true
                top_toTopOf = parent_id
                padding = 10
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // set layout to content view
        setContentView(contentView)
    }
}
Open Source Agenda is not affiliated with "Layout DSL" Project. README Source: wisdomtl/Layout_DSL
Stars
149
Open Issues
4
Last Commit
1 year ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating