Layouts

Layouts are defined in XML. They are associated with an Activity that contains the view logic. Every layout has a top-level container.

Common layouts (ViewGroups):

  • Linear layout: This aligns UI components in a linear order, vertically or horizontally
  • Relative layout: These UI components are aligned relatively to each other
  • List view layout: All items are organized in the form of a list
  • Grid view layout: All items are organized in the form of a grid
  • Scroll view layout: This is used to enable scrolling when its content becomes higher than the actual height of the screen

Common Views:

  • Button: This is a Base class that represents a button linked to the onClick action we define
  • ImageButton: This is a button with an image used as its visual representation
  • ImageView: This is a view that displays an image loaded from different sources
  • TextView: This is a view that contains single or multiline non-editable text
  • EditText: This is a view that contains single or multiline editable text
  • WebView: This is a view that presents rendered HTML pages loaded from different sources
  • CheckBox: This is a main two-states choice view

Assign a handle to a layout for use in code:

 android:id="@+id/my_button"

to access it from code:

R.id.my_button

R is a generated class that gives us access to Reasources.

val x = findViewById(R.id.my_button) as Button

Kotlin has view binding though so you can just do this:

my_button.setOnClickListener { ... }

Other UI components:

  • ConstraintLayout: This views and positions child elements in a flexible way
  • CoordinatorLayout: This is a very advanced version of FrameLayout
  • SurfaceView: This is a view used for drawing (especially when high performance is needed)
  • VideoView: This is set to play video content

results matching ""

    No results matching ""