3

My application has several screens, and each of them has almost the same layout.

I know I can use the "include" tag in xml to avoid rewriting the same layout again, but I also do not want to duplicate the java code of setting the behavior/properties of views and layouts. What is the best practice to be more organized in this case?

Edit: For example in several screens, the first half of the layout is a gallery that scrolls horizontally with text below it. This is the same throughout my app

Harsha Vardhan
  • 446
  • 4
  • 15

1 Answers1

1

If the screens are the same for example. Activity/Fragment

You can create a "generic" parent that handles the logic and use include for the layout.

Or

Create a custom view that uses a layout as content and you can write your logic there.

I create a library that uses this principle. here is a tutorial on how to create a view with a layout file

Gil Goldzweig
  • 1,809
  • 1
  • 13
  • 26