Android Development Android UI and Layouts 1 — Questions and Answers
Question 1: Which layout in Android arranges child views in a single row or column?
- LinearLayout (Correct answer)
- RelativeLayout
- ConstraintLayout
- FrameLayout
Correct answer: LinearLayout
LinearLayout arranges its child views sequentially in either a horizontal or vertical direction.
Question 2: What attribute is used to make a view occupy remaining space in a LinearLayout?
- layout_weight (Correct answer)
- layout_gravity
- layout_margin
- layout_span
Correct answer: layout_weight
The layout_weight attribute distributes remaining space proportionally among views in a LinearLayout.
Question 3: Which view group is recommended for building flat, complex UI hierarchies in Android?
- ConstraintLayout (Correct answer)
- LinearLayout
- TableLayout
- GridLayout
Correct answer: ConstraintLayout
ConstraintLayout allows you to create complex layouts with a flat view hierarchy, improving rendering performance.
Question 4: What is the purpose of the ViewBinding feature in Android?
- To generate binding classes for XML layouts eliminating findViewById (Correct answer)
- To bind data models to UI components using XML expressions
- To connect ViewModel to Fragment lifecycle
- To bind services to activities
Correct answer: To generate binding classes for XML layouts eliminating findViewById
ViewBinding generates a binding class for each XML layout file, providing type-safe references to all views with an ID.
Question 5: Which RecyclerView component is responsible for measuring and positioning item views?
- LayoutManager (Correct answer)
- ViewHolder
- ItemDecoration
- RecycledViewPool
Correct answer: LayoutManager
The LayoutManager in RecyclerView handles the layout strategy for its child views, such as linear, grid, or staggered arrangements.
Question 6: What method must be overridden to provide views in a RecyclerView.Adapter?
- onCreateViewHolder (Correct answer)
- onBindViewHolder
- getItemCount
- onAttachedToRecyclerView
Correct answer: onCreateViewHolder
onCreateViewHolder is called when the RecyclerView needs a new ViewHolder to represent an item, inflating the item layout.
Which layout in Android arranges child views in a single row or column?