UI Basics Flashcards

1
Q

What is a view?

A

A view is a building block for all UI components. It is the superclass of all UI components, containing the capabilities to draw and handle events.

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

What is a layout?

A

A layout defines the visual structure of a UI. It is similar to the difference between a grid and a flexbox in CSS - different layouts will naturally order components in different ways. It is possible to create them both in XML and at runtime.

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

What is the purpose of using layouts?

A

Layouts allow for much cleaner code and a much easier layout experience when building responsive and static UIs.

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

When should you use a LinearLayout over a RelativeLayout?

A

A LinearLayout should be used when the data needs to be horizontally or vertically stacked.

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

What is the difference between a RelativeLayout and a ConstraintLayout?

A

A RelativeLayout positions elements within a relative distance from some other element. For example, an button may be X centimeters below a textbox, or it may be ‘centered’ within another element.

A ConstraintLayout positions elements by using anchors on each side of the object, allowing us to define ‘constraints’ that hold UI elements in place relative to those anchors. It is faster than RelativeLayout as it reduces the need for nested views, thereby decreasing the processing power required.

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

Where can we edit the UI layout of our Activity?

A

Within the XML layout file associated with that activity, as defined in onCreate.

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

How can we edit the values of UI elements at runtime?

A

First, find the component by using findViewById or some other method. Then, we can use built-in methods to edit the values.

e.g. b.setPadding(20, 15, 20, 15)

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

What is a data-driven container?

A

A data-driven container is a type of view allowing for dynamic data elements and interactivity.

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

What is an adapter?

A

An adapter is a component that takes data from a data source (i.e. a database) and separates that data into a dynamic number of data-driven elements within a data-driven container.

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

What is the purpose of ListView and GridView?

A

ListView and GridView are two view elements that contain the functionality for scrolling and picking of items. They are populated by an adapter.

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

What are the two main functions of an AdapterView?

A

To allow for the layout to be filled with data, and to handle user selections.

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

How can we handle user selections?

A

We may use OnItemClickListener, an interface that comes as part of AdapterView. When the item is clicked, the onItemClick method within is called, and the response inside is carried out.

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

What is the purpose of RecyclerView over ListView or GridView?

A

RecylcerView is a type of ListView that supports all forms of layout through different LayoutManagers, allowing it to have all the same functionality as List and GridView.

It is also highly optimised for large and dynamic datasets, reducing memory usage and improves performance when scrolling.

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

What is a ViewHolder?

A

A ViewHolder is an object that stores an item in a RecyclerView and metadata about its place in the View. The layout for this is defined in XML, and it can contain any type of View.

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

What methods do we need to implement for a RecyclerView.Adapter?

A

onCreateViewHolder, to create a new ViewHolder whenever the RecyclerView needs it, and onBindViewHolder, to perform tasks when the ViewHolder is placed where it needs to be.

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

What issues may we face when generalising UI to different devices?

A

One device may be naturally portrait, and another may be landscape. Some may switch between the two frequently. We need to be sure that the UI we design will conform to the chosen orientiation.

16
Q

What are fragments?

A

Fragments are sections of an application’s interface or behaviour. They may be slotted in to the layout of an activity either before or at runtime in order to simplify sections of the UI and make them more recyclable.

17
Q

What are the benefits of using fragments?

A

Reuse throughout the application, elasticity, easier communication, separate handling of activities and events.

18
Q

How could we use fragments to create a two-pane panel?

A

We could make one fragment that contains a ListView of articles, and a second fragment that contains that whole article. Similar to how it looks in Obsidian!

19
Q

What are the fragment lifecycle states?

A

Waiting, running and stopped - exactly the same as an activity.

20
Q

When is onAttach called in the fragment lifecycle?

A

Called when the fragment is first attached to its holding activity.

21
Q

What is the purpose of onCreateView in the fragment lifecycle?

A

Creates the view hierarchy associated with the fragment. This method must return a View that is associated with the fragment’s layout.

22
Q

What is different about a fragment and an activity’s ‘destroy’ stage?

HINT: A fragment has ‘more’ stages.

A

Instead of simply doing onDestroy, a fragment must first onDestroyView, then onDestroy, then onDetach itself from the activity.

It cleans itself up in succession - first the View, then its memory, then it detaches. Think of it like a box slowly having its contents removed.

23
Q

How can we create a fragment?

A

First, create the layout in XML. Then, create a Fragment-inherited class, which has an onCreateView method that returns that XML layout View.

24
Q

How can we load a fragment into an activity?

A

We use the FragmentManager, which allows us to use ‘fragment transactions’ to replace a placeholder View with a Fragment.

The fragment manager also allows us to choose whether or not to add the fragment to the backstack, which is helpful.

25
Q

Who is responsible for creating and removing fragments?

A

The activity that it is hosted within. Each activity has its own instance of FragmentManager. Or, instead of that, we can use findFragmentById to search all fragments inside the Activity.

26
Q

Is it possible to create a fragment with no UI?

A

Yes, it is possible to do this if, for example, we wanted an invisible worker for the activity. In this case, there is no need to override the onCreateView method.

27
Q

What are the two types of menu?

A

Options menu and context menu.

28
Q

What is the difference between an options menu and a context menu?

A

An options menu is the single main menu for that activity, which is used to store user preferences and activity-wide actions.

A context menu occurs on a long-click on an element, and allows for more targeted actions on a UI element, such as selecting an item in a RecyclerView.