Reputation: 10338
I'm a bit confused, when I declare a layout in XML, and I call the:
R.layout.idname
is this considered the ViewGroup?
Upvotes: 0
Views: 658
Reputation: 1
View group: is a combination of views
Layouts: how views should sortup
View group has views inside it, but how the views should be arranged, the arrangement of views is known as layouts.
For examples, linear layout and relative layout are both layout and view group because they have views inside and the arrangement of views in them are known as layouts.
Upvotes: 0
Reputation: 40203
No, Layouts are not same as ViewGroups. While every Layout is a ViewGroup
, there are ViewGroups that aren't layouts (e.g. ViewPager
, ScrollView
). Regarding an XML file in R.layout, it depends on the root element of the XML: if for example it's a LinearLayout
- you'll be able to cast it to ViewGroup
, if it's an ImageView
- it is considered a View
.
Upvotes: 0
Reputation: 495
Not really. It depends on which xml layout you have given R.layout.idname to.
TextView
, ImageView
, EditText
for examples are NOT viewgroups.
FrameLayout
, RelativeLayout
, LinearLayout
etc are considered viewgroups.
A clue is in the name really... viewgroup. a view that can be a grouping of views.
Upvotes: 1
Reputation: 44571
is this considered the ViewGroup?
No, this is the complete layout file.
Are layouts same as ViewGroups?
No, one is the file. A ViewGroup
would be any View
such as a RelativeLayout
, LinearLayout
, etc... that holds other View
s.
A ViewGroup is a special view that can contain other views (called children.)
Upvotes: 1
Reputation: 157457
It depends on the widget you declared inside your layout. For instance you can declare a single TextView
inside your layout. TextView
s are views, not ViewGroup
. If you declare a LinearLayout for instance, it will be a ViewGroup
. If you take a look to the documentation you can see the direct and indirect subclass of ViewGroup
Upvotes: 1