Reputation: 14472
I have a complex project with many layouts (approx 40) and to reduce duplication, I am using a lot of includes.
I have an activity layout in layout-xlarge-land which includes another layout (layout B) which itself is just a set of more includes in a LinearLayout.
My emulator is set to XLARGE and landscape and sure enough, it picks up the activity layout. I've hard coded the activity title in the layout so I can confirm which one is being used.
The problem is that if I put layout B in layout-xlarge-land, the ADT will not preview my layout and gives a "cannot render" error. if I move layout B to res/layout (i.e. with no qualifiers) it works.
My understand is that Android will look for a layout in the qualified folder first then, if not found, use the one in the unqualified folder.
It's a problem because layout B should be different for the various resolutions and orientations.
Am I misunderstanding something or is this a quirk of the ADT/Android? If a quirk, any workarounds?
res
layout layout-xlarge-land activity_layout.xml <---- correctly loaded layoutb.xml <---- "cannot render"
res
layout layoutb.xml <---- renders OK layout-xlarge-land activity_layout.xml <---- correctly loaded
[EDIT] I'm using IDEA but don't see any relevance to the IDE.
[EDIT] From the IDEA log
s.android.uipreview.RenderUtil - InflateException: You must specifiy a valid layout reference. The layout ID @layout/data_panel_all_views is not valid.
This confirms that ADT is looking in res/layout.
Upvotes: 0
Views: 232
Reputation: 14472
This was weird. One of the things I did was to restart IDEA which didn't resolve anything.
I've just rebooted my PC to install some updates and since starting IDEA, it's working as expected.
I've seen some issues with layouts which were fixed by restarting Eclipse. The common element is ADT so I suspect some flakiness in there.
Upvotes: 0
Reputation: 6647
Taking a look at How Android Finds the Best-matching Resource, it tells that you can provide multiple qualifiers and how the best layout is chosen, so in the case you are sorting qualifiers well (which looks like you're doing, as the activity_layout
is correctly loaded), try applying less qualifiers and seeing if those includes
are working. Otherwise, you could think about the dirtiest solution: creating different layoutb
's for each resolution and storing them in the same folder. That would mean each activity_layout
would load it's correct file.
Good luck!
Upvotes: 1