My application has a mobile UI and tablet UI. for tablet UI specific layouts are placed in layout-large folder.
What I noticed recently is, when I change the layout of tablet it changes the XML file of the phone xml file too which is in the layout folder.
I don't know why this happens. How to resolve this issue?? I hope it has something to do with Eclipse.
At the top of the graphical editor, you can select which layout you are editing. In no case should it edit both, though.
Related
Duplicate of this.
I am not able to add comment to the existing question that's why I have ask new question.
There is one solution in the above question "if your Android device is in landscape mode and you are loading a layout the android system will look if this layout file exists in the /res/layout-land folder. If it does not exist in this folder it will load the layout from the normal /res/layout folder."
But some how it is not working for me. I have added folder called land in layout folder also added xml file with same name, but it is still loading xml file from the main layout folder , when my screen is in landscape mode.
Is there any other solution ?
Here is the link of the answer.
It just has to do with SDK version(11 and 13).
I need to know if there is any way that i can test my xml appearence on phone without running the whole app, i mean just the xml file without any action for anything?
No there is no direct way to check the xml without recompiling and running on device.
But you can use graphical Layout editor to check the layout on approximated screens, or can create screen similar to your screen with same DPI and size.
and check it on graphical Layout editor.
NOTE: on device XML is just XML. where as when you compile the XML it is read and transformed to a view based code that is actually your UI.
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.
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!
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.
I have been trying to develop an application in a landscape mode so I placed "android: screenOrientation="landscape" in my Manifest. It worked well, however, the graphical layout of my xml files are still not in landscape mode so I cannot design my UI well. Any help? Thanks
Follow below screenshot
you should design separate UI for landscape mode and put in layout-land folder. check this link
go to res folder in your project, and create a new folder in it name it as layout-land
I am trying to simply alter the setlayout when I rotate my device so that I can have a layout of Views for a particular activity that is suited to the current orientation of the Android device but I am confused about the best way to achieve this.
I have referred to the following android doc:
Handling Runtime Changes
I do not need to save any data from my Activity so don't think I really need to use the onRetainNonConfigurationInstance() method. I tried handling the orientation change myself through the onConfigurationChanged() method, where I find the current orientation then set the layout as required but this results in views that no longer work. Is there something else I need to do in onConfigurationchanged()?
Thanks
To get a different view for landscape as opposed to portrait, you would place your layout XML file in both of the following resource folders:
/res/layout - Portrait
/res/layout-land - Landscape
This is, of course, if you have the same views within both, otherwise you may get some NullPointerExceptions.
You can create a new directory under res called "res\layout-land", create an .xml layout file in both "res\layout" and "res\layout-land" that have the same name. For example: "myLayout.xml". Android will automatically use the layout from the -land directory when in landsacpe orientation and the other when in portrait.
in your projects res folder you should have a layout folder. Create a new folder in the res and call it layout-land. Now create your second set of layout.xml files that are specific to landscape oriented devices. Save them in this layout-land folder. The system will handle the rest for you.
check out this page and scroll down to "Providing Alernative Resources" for more detail about different qualifiers you can use on your res folders.
Edit: What device are you using? I created a quick test project that is nothing but hello world but displays different text from a layout stored in res/layout-land folder.
I tried it once with and once without configChanges="orientation" in the manifest. When I run the app and switch orientations the layouts behave as expected. The layout from layout-land is displayed when device is landscape and layout from plain layout folder is shown when device is in portrait.
The device I tested on is Sidekick 4g. Download the test project and report back how it works on your device if you like.