

By default, these configurations in have the structure android:layout_height for height, for example, android:layout_width In this regard, when you create your ViewGroup, you can further create LayoutParams specific to the way you would wish your ViewGroup to behave.Īndroid comes with default Views and ViewGroups we can use to do a lot of the common tasks we need. Some common parameters are ones that pertain width, height and margin.
#ANDROID STUDIO RECYCLERVIEW VS LISTVIEW ANDROID#
To make these configurations easier, Android provides a class called LayoutParams, which we can use to input these configurations.Īndroid documentation provides some default parameters we would implement when configuring our own ViewGroup. This would be the case if we were developing our own ViewGroup from scratch. For example, TextViews following each other should be have 12dp distance while ImageViews followed by TextView should have a distance of 5dp. We can have different rules for interaction inside the View. The ViewGroup also enables us to define how the children are organized inside the view, for example, are laid our vertically or horizontally. together and the structure that would hold that would be what we call the ViewGroup Var nestedArr = //in our anology, we can now group views Var arr2 = // We can imagine this as another simple view but we could imagine there's one that makes it easy to use numbers we can imagine this as a NumberTextView which doesn't really exist var arr1 = //imagine a simple View as an Array Given that an Array of Arrays is an Array itself, we can see how a ViewGroup can be treated like a View. We can image a View as an Array and a ViewGroup as an Array of Arrays. In this case, the View that’s created at the top level that we add other simple views(we can also add viewGroups) to is called the “parent,” and the views that are added inside are “children”. The ViewGroup class is a kind of View but, unlike the simple View class whose responsibility is simply displaying, the ViewGroup gives us the ability put multiple views into one view, which we can reference as a whole. The View class provides methods we can override to draw on the screen and a means to pass in parameters such as width, height, and our own custom attributes we would want to add to our View to make it behave as we would wish. It’s possible to create our own custom views to be able to achieve more flexibility when developing user interfaces.


EditText extends from the same View class and adds more functionality to enable the user to input data. TextView, for example, has a simple purpose of displaying text content on the screen. These classes are abstract and are extended to different implementations to suite a use-case. The Android platform uses the View and ViewGroup classes to draw items on the screen.
