01 Android Layouts and XML Flashcards

1
Q

Android apps are divided into two parts

A
  1. Resources

2. Java code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Resources include

A
● Layouts (define structure of UIs) 
● Drawables
      o graphics such as PNGs 
      o XML files that describe how to draw Shapes
● Strings 
● Colors 
● Menus 
● Styles (sort of like CSS) 
● Other miscellaneous things
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Java Code

A

● All the logic that runs
● Code you write
● Code you get from the Framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Layouts and Views

A

Every UI “widget” in Android is called a View Views can be “singular”
Buttons, TextViews, Checkboxes, etc
- Views can also be used to lay out other views
● Called “ViewGroups”
● Have child views
● Each ViewGroup has different rules for
organizing its children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Other Info on the Layout

A

match_parent == Make me as big as the thing I’m inside. If I’m the top-most thing, make me as big as the screen
wrap_content == Make me only as big as the stuff I am displaying 60dp == Make me exactly 60 units big*
Dp = Density Independent Pixels (more on density later) * Assuming there is enough space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

android:id=”@+id/my_label”

A

@ Put this in the “id” group
+ Create a new one if it doesn’t exist my_label The name of the id.
On the Java side, this becomes: R.id.my_label

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Finding and Using Views in Java

A

In an Activity
TextView myText =
(TextView)findViewById(R.id.label)
In Fragments, or if you have a ViewGroup and want to find its children
Button button =
(Button)findViewById(R.id.my_button)

• The cast to Button or TextView is needed
because the declared return type is View
• FindViewByID is slow, so it is best to do it
once for each control in the onCreate
function, and never again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Inflating Resources

A

Each screen in an Android app implemented using a Java class called an Activity*

When an Activity is created, you tell the Android SDK which layout file to use

The conversion from XML to Java is called “inflating”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Inflating Resources (resource id)

A

Whenever your app needs to create UI, your Java code specifies what layout to use by providing a layout “resource Id”

R.layout.activity_main

R = Your app's resources 
layout = pick something in the "layout" folder(s) 
activity_main = The name of the layout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Inflating Resources (layout file)

A
Choices, choices... Android automatically picks the layout file that best fits the "current configuration" of the device 
● Landscape vs. Portrait 
● Language 
● Screen Size 
● Screen Density*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Inflating Resources (name, structure)

A

All resources are assigned an ID

Multiple versions of a resource can exist

Structured according to the type/folder the resource is in

Anything with the same name, but in different folders, get assigned the same ID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Creating Views in Java

A

Its possible (but usually not recommended) to create Views directly in Java

You have to manually code each device configuration

LayoutParams are a pain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Beginner Views to Know

A
TextView 
EditText 
Button 
FrameLayout 
LinearLayout 
RelativeLayout (Lab 1) 
ScrollView / HorizontalScrollView
How well did you know this?
1
Not at all
2
3
4
5
Perfectly