2

As we can read here there is very small difference between ViewBinding and Databinding.

  • The data binding library processes only data binding layouts created using the <layout> tag.

  • View binding doesn't support layout variables or layout expressions, so it can't be used to bind layouts with data in XML.

Are there any other differences that developers should be aware of? Why create something new with such a small difference?

Someone please explain

user158
  • 12,852
  • 7
  • 62
  • 94

3 Answers3

5

Why create something new with such a small difference?

Build times for view binding are much lower than for data binding, because there is a lot less work involved. For small projects, this may not matter. For large projects, the impacts on build times can be substantial.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Advantages of viewbinding is speed and efficiency. It has a shorter build time because it avoids the overhead and performance issues associated with databinding due to annotation processors affecting databinding's build time.

Pratik Fagadiya
  • 1,195
  • 7
  • 21
0

Here is one of the reasons why you might prefer View Binding over Data Binding:

The data binding library processes only data binding layouts created using the <layout> tag. Data binding layout files are slightly different and start with a root tag of layout followed by a data element and a view root element

And this causes problems when intending to use merge:

Data binding doesn't support include as a direct child of a merge element. For example, the following layout isn't supported:

<?xml version="1.0" encoding="utf-8"?> 
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:bind="http://schemas.android.com/apk/res-auto">    <data>
       <variable name="user" type="com.example.User"/>    </data>    <merge><!-- Doesn't work -->
       <include layout="@layout/name"
           bind:user="@{user}"/>
       <include layout="@layout/contact"
           bind:user="@{user}"/>    </merge> 
</layout>
Community
  • 1
  • 1
Zohaib Amir
  • 3,482
  • 2
  • 11
  • 29
  • it does support include now – user158 Nov 04 '19 at 13:17
  • @user158 it doesn't support **include inside merge** – Zohaib Amir Nov 04 '19 at 13:18
  • it's possible please read [here](https://stackoverflow.com/a/58696104/7356355) I do not think currently `include`, `merge` tags work with ViewBinding since bugs are reported [here](https://issuetracker.google.com/issues/143729912) and [here](https://issuetracker.google.com/issues/143683987) – user158 Nov 04 '19 at 15:10