I am making my 1st ever android app using android studio,
Everything works correctly except switching between portrait and landscape layouts.
What code do i need to insert and, where to get my app to see the layouts I have made.
Thanks
Michael
You have to create a new folder called layout-land and place it in there.
Ex:
Your layout's current location is layout/my_layout.xml, you would place the corresponding landscape layout in layout-land/my_layout.xml
Check: http://developer.android.com/guide/practices/screens_support.html under "Using configuration qualifiers"
Similar Question:
How do I specify different layouts for portrait and landscape orientations?
Related
I know you can set specific layouts for a device like this:
if(android.os.Build.MODEL.equals("Galaxy S II")){
setContentView(R.layout.resultsGS2);
}
else if(android.os.Build.MODEL.equals("Nexus 7")){
setContentView(R.layout.resultsN7);
}
else{
setContentView(R.layout.results);
}
But what I want is to make a layout for all devices that have similar screen size/dimensions. I have been looking at this: http://developer.android.com/guide/topics/resources/providing-resources.html and I tried renaming the layout folder many different things and whenever I try to edit an xml file in the new layout folder I made and I change the device preview it keeps changing back to the default layout. I am using android studio, and basing the need to make a new layout off of the device previews that it shows. Is there is an easier way to do this besides making a layout for each specific device?
This can be done by having different layout folders and calling them layout- + screen size name and then edit the layouts inside these folders to match the screen size you are targeting.
So for example if you wanted to target something such as the galaxy nexus (320dpi) you would create a folder called layout-xhdpi and all the device specific layouts will be placed in here. And then if you were to run this in an emulator or a physical device you would see the layout that you made specifically for that screen size.
I have a android app layout for tablet. Its layout is 'landscape' based (i.e. it looks the way i want when I run on tablet (by default landscape).
But when I run the same app on a phone, android runs in portrait mode, (it squeeze my 'landscape' layout into a portrait ).
I have tried putting 'android:screenOrientation='landscape' in my activity in my Manifest file. But that does not fix it.
Basically, what I want is when I rotate the phone by 90 % (the width is > height), I want the phone layout looks the same as what i see on tablet (which is landscape by default).
How can I do that? android:screenOrientation='landscape' does not work.
Basically, I want some thing the game 'AngryBird', it always runs in landscape mode regardless it is phone or tablet and whether the phone is rotated.
I think you need to use 2 flags, not just one.
First is
android:screenOrientation='landscape'
Second is
android:configChanges="orientation"
First will tell android to run activity in landscape mode, where as second will tell android that do not change the orientation even when user rotates the phone. Basically with 2nd flag you are overriding orientation config changes.
Haven't done this myself, but instead of putting the main.xml layout in res/layout, try putting it in res/layout-land, so it will display this layout in landscape mode, and in res/layout-port, maybe a portrait alternative to main.xml?
Create folder \res\layout-land\ and place there your XML file with landscape layout. Phone choose between portrait and landscape layouts automatically.
Add this line in the onCreate method before you call setContentView:
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
I am developing a app running at android pad,I need fix the layout horizontal.
I know that with java,I could set a attribute in a xml file,but I couldn't find a file like this in my flex project.
So how could I fix the app horizontal?
Set the <aspectRatio> to landscape in your application's descriptor file.
You can find that file directly in the src folder under yourAppName-app.xml.
Keep in mind that the current version of Flash Builder has a bug which displays landscape marked apps as portrait in the Flash Builder emulator. If you deploy the application, the correct aspect ratio is set, though.
AndroidManifest.xml -> Tab Application -> Application Nodes -> choose activity and in the field "Screen orientation" choose landscape.
Place layouts for portret mode in /res/layouts/
Place layouts for landspace mode in /res/layout-land
Layouts xml must have same neme, for example mail.xml
I have downloaded the google io application and I noticed that for landscape layout, its only the dashboard layout that have a landscape layout (in the layout-land folder).
My question is the following, is it for all the layout available in our project that we must create a landscape layout or it is only for the dashboard layout?
Thanks.
Kind Regards.
You are allowed to create a landscape layout for any layout in your app. You should do this when you want to have a different layout in portrait vs. landscape. Sounds to me like the Google IO app specifies a different landscape layout for only one screen (the home screen/dashboard), presumably because that's the only screen the developers felt needed a different landscape layout. Point is, it's up to you which screens have alternate layouts.
It depends on the data you have to show.
Sometimes there is more data which can be shown because of extra width in landscape and you have to compress data vertically in landscape. For such cases use different layouts
I am a newbie to the android world, and as of today I completed my first application.
I test my work on a physical device, and quite recently it has came to my attention that whenever I turn/rotate my device, my application tries to adapt itself to the new resolution 800x400.
Since I have designed the whole app for 400x800 resolution, this change messes up the original design, as well as sending a new call to "onCreate" method of the last activity it was on, before turning/rotating the device.
I would like to learn whether it is possible or not, or which class I should use to stop the adaption to resolution.
This line (in AndroidManifest.xml) will lock the activity in portrait mode:
<activity android:name="MyActivity"
android:screenOrientation="portrait" />
There are things that you can do to make your layouts work well in different orientations and resolutions, such as using dips instead of pixels to measure your views.
When you have time, consider making layout files for landscape mode. Create a "layout-land" directory within your res directory and drop he landscape layout files there, using the exact same file names for their portrait counterparts.