mskw
mskw

Reputation: 10338

Are layouts same as ViewGroups?

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

Answers (5)

Basit Ali
Basit Ali

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

Egor
Egor

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

Unknownweirdo
Unknownweirdo

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

codeMagic
codeMagic

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 Views.

From the docs

A ViewGroup is a special view that can contain other views (called children.)

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157457

It depends on the widget you declared inside your layout. For instance you can declare a single TextView inside your layout. TextViews 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

Related Questions