Professional Documents
Culture Documents
Pert 4 - Views Layouts
Pert 4 - Views Layouts
Advantages : Rules :
o XML is used to transfer the data between o Every XML have a root element
multiple technologies
o Every XML element must be properly
o XML is used to textual database nested
o XML is used to deployment descriptor o Shouldn’t start with a number and any
spaces between the tags
VIEW AND VIEWGROUP
View
Parent class for all UI Elements
Everything you see is a view
Views
ViewGroup
View that contains other View
Base class for Layouts and other Containers
WHAT IS A VIEW?
Views are Android's basic user interface building blocks.
o display text (TextView class), edit text (EditText class)
o buttons (Button class), menus, other controls
o scrollable (ScrollView, RecyclerView)
o show images (ImageView)
o subclass of View class
VIEWS HAVE PROPERTIES
o Have properties (e.g., color, dimensions, positioning)
o May have focus (e.g., selected to receive user input)
o May be interactive (respond to user clicks)
o May be visible or not
o Have relationships to other views
EXAMPLES OF VIEWS
Button CheckBox
RadioButton
EditText
Switch
SeekBar
VIEWS DEFINED IN LAYOUT EDITOR
●XML Files
● Programmatically
VIEWS DEFINED IN XML
<TextView
android:id="@+id/show_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/myBackgroundColor"
android:text="@string/count_initial_value"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/count_text_size"
android:textStyle="bold"
/>
CREATE VIEW IN KOTLIN CODE
context
In an Activity:
val text_view: TextView = TextView(this)
text_view.text = "Hi, i am a TextView"
VIEWGROUP VIEWS
A ViewGroup (parent) is a type of view that can contain other views (children)
ViewGroup is the base class for layouts and view containers
o ScrollView—scrollable view that contains one child view
o LinearLayout—arrange views in horizontal/vertical row
o RecyclerView—scrollable "list" of views or view groups
HIERARCHY OF VIEW GROUPS AND VIEWS
Root view is always a view group
ViewGroup
cancel Search
Search
COMMON LAYOUT CLASSES
Superclass-subclass relationship
Parent-child relationship
BASIC ATTRIBUTES
Size
Gravity
Margin and Padding
BASIC ATTRIBUTE - SIZE
Match_parent
Wrap_content
In spesific dp
100 px 200 px
By By
100 px 200 px
ATTRIBUTE - GRAVITY
Layout_gravity
Gravity
Padding
Content
m
Element
padding