UI Basics Flashcards
What is a view?
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.
What is a layout?
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.
What is the purpose of using layouts?
Layouts allow for much cleaner code and a much easier layout experience when building responsive and static UIs.
When should you use a LinearLayout over a RelativeLayout?
A LinearLayout should be used when the data needs to be horizontally or vertically stacked.
What is the difference between a RelativeLayout and a ConstraintLayout?
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.
Where can we edit the UI layout of our Activity?
Within the XML layout file associated with that activity, as defined in onCreate.
How can we edit the values of UI elements at runtime?
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)
What is a data-driven container?
A data-driven container is a type of view allowing for dynamic data elements and interactivity.
What is an adapter?
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.
What is the purpose of ListView and GridView?
ListView and GridView are two view elements that contain the functionality for scrolling and picking of items. They are populated by an adapter.
What are the two main functions of an AdapterView?
To allow for the layout to be filled with data, and to handle user selections.
How can we handle user selections?
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.
What is the purpose of RecyclerView over ListView or GridView?
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.
What is a ViewHolder?
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.
What methods do we need to implement for a RecyclerView.Adapter?
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.