shhp
shhp

Reputation: 3693

What is tag <view> in layout xml used for?

I notice that there is a tag <view>(not <View>) which can be used in Android layout xml. When I add such a tag in a layout xml, the app can be successfully compiled but crashes when running. So what is this <view> used for?

Upvotes: 9

Views: 5520

Answers (2)

laalto
laalto

Reputation: 152807

view is an alternative way for specifying a view to inflate. You need to combine it with class attribute to specify the class name.

This is "useful" if your view class is an inner class and you cannot use something with a $ in the tag name in XML. (Having inner classes as Views you inflate is not a very good idea though.)

For example:

<view class="your.app.full.package.Something$InnerClass" ... />

Reference: http://androidxref.com/5.0.0_r2/xref/frameworks/base/core/java/android/view/LayoutInflater.java#696

Upvotes: 6

Deep Singh
Deep Singh

Reputation: 147

View is widget of android that is use to add any kind of view.Like in problems when we use scrollView in a activity and at bottom of activity there is buttons ,That time we add view to looks better.We can set any kind of color to View . for exp This will make a View of 20dp height.

Upvotes: -1

Related Questions