Android Different Menu Resources - android

Doe's Android support multiple menu folder (e.g. like /drawable-hdpi and /drawable-mdpi)? If so what types are supported (land, xhdpi, swXXXdp)?
P.S. Sorry for such a goofy question...
Edit 1: For example I have different layouts. Depending on that I can have different menu resources, no? As a start it would be nice to have sooch folders:
res/menu
res/menu-land
res/menu-xhdpi
res/menu-xhdpi-land
res/menu-sw600dp
The first two work fine... but when I try to add the other ones the app work instable on different devices.

Yes. even in portrait and landscape modus:
menu-land-mdpi
menu-port-mdpi
menu-land-hdpi
menu-port-hdpi
menu-land-xhdpi
menu-port-xhdpi

yes. Don't see any point not to support it, documentation here provides no restrictions on it (I myself at least have used -land qualifier)

The menu can be used like layout folder, you can add menu-land, menu-port ... also, you can use specific menu for multi langue, like menu-fr, menu-en to rearrange items based on phone language...

Related

tablet/handset layout structure with fragments

In this article http://developer.android.com/guide/practices/tablets-and-handsets.html
we use res/layout/main.xml with one fragment for handsets and res/layout-large/main.xml with two fragments for tablets. We must check if second fragment is in the layout to define if app runs on tablet or on phone.
I have 4 layout (2 for phone and 2 for tablet):
layout-port
layout-land
layout-sw600dp-port
layout-sw600dp-land
I check screen orientation to define if display is in portrait or landscape mode and check if layout contains a fragment to define if it is tablet or phone.
Is there any better way to work with layouts and fragments?
Is it possible to use one layout if we have two fragments for example http://i.stack.imgur.com/FtzKs.png and if a phone display doesn't fit both of them to show only the first one?
Thanks in advance! :)
What you're showing there is indeed possible! That is something called a Master Detail Flow (if you're developing in Eclipse with adt, check out he new activity wizard, which provides this as a template option).
This layout is basically just two fragments inside an activity (or, now, as of android 4.2, they can be nested in another fragment as well!) that interact with each other in a certain way. To create the layouts you linked to, one would detect whether the device is a phone or a tablet, and then set the visibility of the two fragments in different situations accordingly.
You will find a number of methods for detecting screen size here, whether you want to use screen size in inches, pixels, or the manufacturers' default categories.
And properties like visibility and sizing can be set programmatically using Layout Params and its various subclasses.
In any particular case, whether you choose to use multiple layouts to support different screen sizes or to do more of it programmatically is up to you. Personally, I think that it is always a good practice to design your code modularly and then use layouts to put all the pieces together (it'll save you a lot of headaches down the line if you decide you want to change things up). But either way, supporting more devices will always require more code, and there are no two ways around that...one of the curses of android development :P

How does the ADT select layout XMLs depending on device size and orientation?

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.

How to get GUI same as Veriticall direction or in Horizantal direction?

I developed a application. In that i get GUI perfect in portrait, but when i tern my emulator(pressing Ctrl+F11) some text and buttons will be miss ordered. i searched so many sites but i am not get the solution.
Please any one give a solution.
Thank You.
For solving these problem you should make two layout for different different
1-: create a new folder in side the resource is layout-land then put your layout for landscape in this folder.
2-: another one is use for portrait mode its put in layout folder.
you can create your application to support landscape mode by creating different layouts.
simply you can create a folder in your res folder like this -> /res/layout-land and copy your layouts and make necessary changes(for landscape) to it.
please read the documentation for further details
tutorial

Android Layout qualifiers don't work?

I am developing an android using the API Google Tv Addon, i wanna use the screen qualifiers no touch, i created a folder under /res/ called layout-notouch, i named my layout test.xml, in my activity when i put setContentView(R.layout.test) the application crash. how could i use this screen qualifier. Or otherwise, could i set qualifiers programatically. you can take a look here enter link description here
You can use layout-large-notouch for layout and drawable-land-xhdpi for drawables to target Google TV.
I figured out that the layout-notouch is not working.You can find the google bug report at this links https://code.google.com/p/android/issues/detail?id=20087
Some people are suggesting to use resource qualifiers layout-tvdpi-notouch (720) & layout-xhdpi-notouch (1080),layout-large-notouch.
But not sure the suggestion is working.
I'm not entirely sure about what I'm about to say, but it seems to me that "notouch" qualifiers will not work because current Google-TVs support some sort of touch. You have a trackpad that acts as a mouse and you can click on things, simulating "touch" events.
If in the GTV emulator you edit the avd settings, you can specifically declare the "touch screen type" as "notouch". Then, if you run your application under those conditions you will see that the "notouch" qualifiers work. This means that by default "touch-screen type" is set to "touch" instead of "notouch".

Universal App for both tablets+handsets

I am developing a single application for both tablets and for handsets..My app is currently running fine on handsets(as according to layouts and all)..but i have no idea for how to distinguish it for handsets/tablets. I have seen some of the answers in Stackoverflow.com too, in which some people answered that use different layout-large,layout-xlarge.
but if the layout differs and we follow the above scenario,then in programming,it is written setcontentView(R.layout.---).
So we have to mention here also that setContentView(R.layout-large.---)..I am so confused with this..Can anyone suggest me something...
you only need to name the folder differently those contain same nameLayout.xml
like so
--layout
-- myLayout.xml
--layout-large
-- myLayout.xml
--layout-xlarge
-- myLayout.xml
on code, you only need to use
secContentView(R.layout.myLayout);
android will find the right one for you.
The android os will select the appropriate folder based on the device dimensions and other properties.
So you can keep the resource name same in all the folders and android will pick from the appropriate folder.

Categories

Resources