Android - View (UI Widget|Component)

> Android

1 - About

A view represents a a widget.

All the UI elements extends from the view class

  • a container (viewgroup) is a subclass of a view object
  • a simple widget is also a subclass of a view object.

Views are rectangle on the screen (same concept than box in CSS) where you may or may not view the borders.

A View occupies a rectangular area on the screen and is responsible for:

If you want to group simple widgets, you need a container descending from a ViewGroup


3 - ID

4 - List

5 - Properties

5.1 - Visibility

5.2 - Dimension (Width and Height)

Width and height can have only two values:

  • wrap_content
  • or match_parent

There is then 4 possible combinations and possible outcomes when the view is in a parent (green)

5.3 - Gravity

Gravity of a view (Red) in a parent (green)


5.4 - Padding vs Margin

6 - Type

6.1 - Scroll

ScrollView: Extension of the FrameLayout class (meaning you should place one child in it containing the entire contents to scroll) that allows the user to scroll vertically to reveal more content than can be displayed on screen at once. The ScrollView is often used to contain a vertically oriented LinearLayout into which you can place any linear layout that in turn arranges each item it contains into a vertical list.

6.2 - List

7 - Management

7.1 - Get

by id

Button myButton = (Button) findViewById(;