I am making an application and I just began using Fragments finally, after reading all of the documentation, I got to here. I designed the application so in portrait mode it is two activities, the chooser and the details, while in landscape left is chooser right is details, on a tablet. Now, this works fantastic like in this image:
however, now when I turn the Handset into landscape, it does the same thing as tablet does in landscape, has the two fragments. First, I would like to know should I leave it as the two fragments on the handset too? Would this be the "best practice"? If not, I would like to know how to go about making the landscape like the portrait without messing up tablet landscape.
Thanks
You'll need to have two separate layouts, one in a layout-port (for portrait) and one in layout-land (for landscape). Your portrait layout should contain just one fragment. In your activity you'll need to check for the presence of that fragment, or the view that contains it (if you are using FrameLayouts), and act accordingly.
See this from the developer site.
Related
I'm developing an Android Application which is locked to portrait mode for phones. In one part of the application, the user can look at some nice Graphs. In this part (only), it would be nice to allow the user to change to landscape mode - if he wants to.
I know this would be quite simple if the Graphs were contained in their own activity, but unfortunately, they are not. They are shown by Fragments which in turn are shown in a somewhat complex Tab Layout.
In other words; I want to have to whole app locked to portrait mode except when the user is in a specific Fragment. Then I want to allow him to allow him to change to landscape mode (Not neccessarily by rotating the device, other solutions are welcome too). When the user navigates away from that part of the app from Landscape mode, the portrait mode should be restored.
Is there any way this can be achieved?
you can do it dynamically this way :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
I have to write an app for tablet and for phones too. The two app has the same functionality, but they have absolute different GUI.
For example the phone have 2 button on the main screen, but the tablet going to have 5, because we would like to use the space what we have. I know, I˜m able to define different layouts, depends on dpi, but how should I handle the layout-s in the Activiies? I think, to use if(sdkVersion >=11) bla..bla... is not will works through the hole code and the hole project! Is this the situation where I have to use multiple application support ?
readed articles:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
http://developer.android.com/guide/market/publishing/multiple-apks.html
I don`t understand how should I handle this problem... please if you able help , thx
Put your tablet layouts in res/layout-large/. Put your phone layouts in res/layout/. Name them the same. Your activities will load the right ones based upon the device they run on. When you call findViewById() to retrieve the extra buttons, and see that you get null back, ignore them.
You may need additional layouts in places like res/layout-large-land/ (landscape for tablets), res/layout-xlarge/ (if you want to handle 10+" tablets differently than stuff in the 5-9" range), res/layout-small/ (if you want to handle <3" screens), etc.
I am hoping to save some time with a project and wonder if this is possible to do.
Currently there are some android phone screens that have already been developed by a former colleague. I am developing a new screen for a tablet that needs to have the content of an existing screen that he developed appear as a sub-screen (say a little box in the bottom right corner of the screen. This is aesthetically ok because the existing screen is small (phone). The screen I am developing is for a 10.1" tablet, so it only takes up a tiny portion of my screen.
However, the problem is that he had the screen all coded up in a nicely and integrated with an associated Activity. I am hoping to just reuse it by calling an Intent from my screen/activity unit, modifying it as little as possible.
QUESTION: Is it possible to have an activity appear as a subscreen of another activity?
Mind you I know that you can launch a fire and forget activity from one screen with an Intent + startActivity(). But that will only take the new screen appear on top of the old screen.
Where as I want the new screen to appear as a subscreen of the existing screen. Any idea?
All pointers and recommendations are appreciated. TIA
You're looking for Fragments!
From the Android documentation:
A Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities. You
can think of a fragment as a modular section of an activity, which has
its own lifecycle, receives its own input events, and which you can
add or remove while the activity is running.
If you're developing for devices running Android versions prior to 3.0, take a look at the compatibility library, which allows the use of Fragments in versions 1.6 onwards.
Further, if you're developing for phones and tablets, you can reuse the same Fragment in both interfaces.
My app has to support landscape/portrait mode only for tablets, phones will only support portrait mode. What is the best way to implement this?
Options that I am considering:
a) using two apk files, one for phones and one for tablets. The one for phone will lock landscape mode in the manifest
2) using one apk file. Detect that device is a phone, lock landscape mode inside each activity.
any advice will be appreciated.
Regards
You can use a SuperClass for activities and implement this https://stackoverflow.com/a/9629127/710162 on, for example, onCreate().
I have written a dock app that utilizes the stock dialer within android but it always displays in portrait mode is there a snippet that I must include to get the dialer to respond to being in the dock. How do I call the layout that the stock dock program does?
Thanks in advance.
You can tell the user to put it in a dock, I suppose. If the device is in landscape mode, and the application does not support landscape mode (e.g., the dialer on my Nexus S), that is just the way it is.
More generally, you have no right to dictate how third party applications should look and behave, any more than other people have the right to dictate how your application should look and behave. The application will look and behave how its developers designed. If they have different layouts for landscape or being in some sort of dock, they will use those layouts... when they are in landscape or in some sort of dock.