3

My app uses a library project "core project" with the application core, then little projects "child projects" for the particularities of each supported device, ie. Amazon Fire TV, Kindle tablets, regular google tablets, phones, etc.

Let's say, I have a Custom View class MyCustomView that inflates programmatically a layout R.layout.layout_customview. Both are on the core project:

public class MyCustomView {
     .
     .
     inflate (R.layout.layout_customview);
     .
     .
}

I'd like to create an alternative layout for this custom view in one of the child projects, so I created the layout_customview.xml and put it into the child project res/layout.

However, the custom view keeps inflating the other one under the core project res/layout (sounds logical after all, as they both reside in the same project).

Is there a way to change this behavior? ie. "override" xml layout files, or do I have to give the alternative layout a different name, extend the class, etc..?

rupps
  • 9,712
  • 4
  • 55
  • 95

1 Answers1

3

In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

Managing Projects

I guess the better course here is just to duplicate the xml in your projects.

prettyvoid
  • 3,446
  • 6
  • 36
  • 60
  • 1
    humm... however that's not happening, can it be because the class using the resource resides in the library project as well? – rupps Oct 23 '14 at 00:27
  • What is happening exactly? Can you clarify again the place of the class and the place of the xml? – prettyvoid Oct 23 '14 at 00:32
  • All stuff is in the core project (library project). I create a child project and just create a XML with the same name, but the class keeps inflating the one from the library project! The link you posted is clear, it should be inflating the other one! – rupps Oct 23 '14 at 00:36
  • Try creating a new project and then adding your 'library' as a module? http://stackoverflow.com/a/16617332/2058534 . I haven't worked with this scenario but I'm guessing that your library is being read as the main app? – prettyvoid Oct 23 '14 at 00:44
  • at the end I just did it the old-skool way, ie, extending the class & using a different name, my projects are pretty complex and I'd lose a lot of time for this experiment if I have to create a new one, etc.. And I'm suspecting it may be related to the resource being loaded from a different resolution folder, I have like 15 folders of those ... I'm accepting your answer because it answers the question with the official docs from Android, so my problem should be elsewhere ! – rupps Oct 23 '14 at 00:50
  • It's probably something to do with the structure. In normal cases you should be able to redefine any resource from the library just fine. Good luck – prettyvoid Oct 23 '14 at 00:54