Creating a layout implementation
In most applications, you'll find that a combination of the ConstraintLayout
, CoordinatorLayout
, and some of the more primitive layout classes (such as LinearLayout
and FrameLayout)
) are more than enough to achieve any layout requirements you can dream up for your user interface. Every now and again though, you'll find yourself needing a custom layout manager to achieve an effect required for the application.
Layout classes extend from the ViewGroup
class, and their job is to tell their child widgets where to position themselves, and how large they should be. They do this in two phases: the measurement phase and the layout phase.
All View
implementations are expected to provide measurements for their actual size according to specifications. These measurements are then used by the View
widget's parent ViewGroup
to allocate the amount of space the widget will consume on the screen. For example, a View
might be told to consume, at most, the screen width. The View...