Android Basic UI-2019
Android Basic UI-2019
File: res/layout/activity_main1.xml
Linear Layout: Horizontal
res/layout/activity_main2.xml
Relative Layout
In android, RelativeLayout is a ViewGroup which is used to specify the position
of child View instances relative to each other (Child A to the left of Child B) or
relative to the parent (Aligned to the top of parent).
res/layout/activity_main2.xml
Relative Layout
Attributes to control the relative position of views within a Relative Layout.
UI Programming with Widgets
• Widgets are an element in a Graphical User Interface
(GUI)
– not to be confused with app widgets placed on the home
screen, mini version of app
• Widgets are building blocks
• User interacts with a given widget
• Often use prebuilt widgets
– Advanced developers create their own (Chris Renke,
Square)
Widgets
• Including:
• Text Views
• Buttons
• Check Boxes
• Spinners (drop down
menus)
• and many, many more
Common Widgets for Input
Control
Widget Attributes
• Size
– layout width
– layout height
• Margin
• Padding
in program
Dimension of Widgets
A dimension value defined in XML. A dimension is specified with a number
followed by a unit of measure. For example: 10px, 2in, 5sp.
This is like the dp unit, but it is also scaled by the user's font
size preference. It is recommend you use this unit when
specifying font sizes, so they will be adjusted for both the
screen density and the user's preference.
Dimensions: pt
Points
• Developer list
– use ArrayAdapter connected to array
– best practice: put array in array.xml file
AutoComplete Using Array
Spinner Controls
• Similar to auto
complete, but user
must select from a set
of choices
Spinner Control
strings.xml in res/values
Simple User Selections
• CheckBox
– set
android:onClick attribute or create a
ClickListener object, override
onClick method, and register it with
the checkbox
• Switches and ToggleButton
– similar to CheckBox with two states,
but visually shows states
– on and off text
RadioButton
• Select one option
from a set
• set onClick method for
each button
– generally same method
• Collected in RadioGroup
– sub class of LinearLayout
– vertical or horizontal
orientation
Pickers
• TimePicker and DatePicker
• Typically displayed in a TimePickerDialog
or DatePickerDialog
– dialogs are small windows that appear in
front of the current activity
Indicators
• Variety of built in indicators in addition to
TextView
• ProgressBar
• RatingBar
• DigitalClock
• AnalogClock
SeekBar
• a slider
• Subclass of progress bar
• implement a
SeekBar.OnSeekBarChangeListener to
respond to changes in setting
INTERACTING WITH WIDGETS
Interacting with Widgets
• Some widgets simply display information.
– TextView, ImageView
• Many widgets respond to the user.
• We must implement code to respond to
the user action.
• Typically we implement a listener and
connect to the widget in code.
– logic / response in the code
Example - Display Random Image
• App to display crests TextView
of British Premier
League Football Spinner
teams
• Allow user to select ImageView
team from spinner
control Button
Padding is the space inside the border, between the border and
the actual view's content.
Controlled by android:padding property.
Margin
Padding
Margin and Padding
RelativeLayout
Alternative?
TextViews?
SeekBar
Layout
• TableLayout
row 0
row 1
row 2
row 3
row 4
row 5
Color Resources
• columns 0 indexed
• columns 1, 2, 3 stretch to fill layout width
• column 0 wide as widest element, plus
any padding for that element
Initial UI
• Done via some Drag
and Drop, Outline
view, and editing
XML
• Demo outline view
– properties
Changes to UI
• change bill total and
seekbar to span more
columns
• gravity and padding for text
in column 0
• align text with seekBar
• set seekBar progress to 18
• set seekBar focusable to
false - keep keyboard on
screen
Changes to UI
• Prevent Editing in
EditText
– focusable, long clickable,
and cursor visible
properties to false
• Set text in EditText to
0.00