Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 926
shhp Avatar asked May 11 '15 12:05

shhp


People also ask

What is layout tag in XML?

The <layout> tag must be the root tag when you are using DataBinding . Doing so you are telling the compiler that you are using DataBinding and your layout will have special tags like <variable> or <import> , so you have to embed your layout within that tag.

What is the function of the layout tag?

The layout container tag tells Android Studio that this layout should take the extra processing during compilation time to find all the interesting Views and note them for use with the data binding library.

What are tags used for in Android Studio?

An NFC tag is a passive NFC device, powered by the NFC field of this Android device while it is in range. Tag's can come in many forms, such as stickers, cards, key fobs, or even embedded in a more sophisticated device. Tags can have a wide range of capabilities.

What is the difference between tag and ID in views?

Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.


1 Answers

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

like image 139
laalto Avatar answered Oct 13 '22 20:10

laalto