Skip to content

Instantly share code, notes, and snippets.

@smoralb
Created March 31, 2022 18:24
Show Gist options
  • Save smoralb/a64ec3c06e5a706b35f115c94a0f24a4 to your computer and use it in GitHub Desktop.
Save smoralb/a64ec3c06e5a706b35f115c94a0f24a4 to your computer and use it in GitHub Desktop.
Creating a layout withint the need to create an XML file
override fun onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
// creating LinearLayout
val linLayout: LinearLayout = LinearLayout(this)
// specifying vertical orientation
linLayout.setOrientation(LinearLayout.VERTICAL)
// creating LayoutParams
val linLayoutParam: LayoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// set LinearLayout as a root element of the screen
setContentView(linLayout, linLayoutParam);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment