Hai Hack
Hai Hack

Reputation: 1018

Apply View Binding for only one layout

I have just started using View Binding in my project. In order to find out whether it suits to my project and my coding behaviour, I want to apply View Binding for only one layout.

By default, it generates classes for each XML by default. This could be a large overhead if View Binding is not used in all classes.

In addition, if it goes well, I want to gradually replace Butter Knife with View Binding. It should be better to choose which layout will use View Binding than choosing which layout will be ignored.

Upvotes: 2

Views: 597

Answers (1)

Amir Hossein Mirzaei
Amir Hossein Mirzaei

Reputation: 2375

you can ignore other generated binding classes and don't use them for your layout and use one specific binding class in your view, fragment, or activity as a replacement for butterknife in that specific class and let other classes use the Butterknife as they don't conflict each other

if you enable ViewBinding it will have an impact on the APK size and also on the Build time of your project but the impact doesn't seem to be annoying and the benefits of the view binding are a lot even if you don't use the generated class the only way I can think of is If you want a layout file to be ignored while generating binding classes, add the tools:viewBindingIgnore="true" attribute to the root view of that layout file

also, I don't see any conflict between Butterknife and viewBinding if you want to test it in a short period of time but in practice, you should use one of them

Upvotes: 3

Related Questions