android:screenOrientation ? Can you go landscape only on high resolution devices? - android

Is there a technique to allow landscape only on large device?
I can set the manifest.xml file for the activity to rotate based on the sensor, eg
android:screenOrientation = "sensor" but this does not provide the behavior I'd like.
For instanced I'd like to allow a user to go to Landscape mode in a tablet device, but not on smaller resolution device (because the UI would look awful).
From what I can tell, there is no way to respond dynamically (eg at run time) if an orientation is acceptable. Or is there?
Am I missing something? Thanks in advance!

Could you do it with the resource folders:
For smaller landscape - default:
/layout/main.xml
main.xml root layout: orientation="portrait" (forcing portrait here instead of in the manifest)
For high res allowing portrait:
/layout-port-hdpi/main.xml
main.xml will be portrait hdpi only
This is the article you can get idea's from: ResourceTypes

Providing resources specific to large streens is built into the Android resource XML. Resource directories may be suffixed with -<suffix> to qualify that they are specific to a class of device capability, locality, time of day, and more. Specifically, you'd be interested in the screen size qualifier, which supports the values large and xlarge for just the purpose of creating special conditions for screens larger than 4 and 7 inches respectively.
For specifics on how to support multiple screen sizes, see this guide which comes directly from the developer manual.

Related

Configuration qualifers - Multiple screen size

I'm creating an application for smartphone tablet and televison.
I'm creating my different displays, but I can not differentiate the tablet from the television.
I read https://developer.android.com/guide/practices/screens_support.html
I have tried many things, large,xlarge sw720dp, W1024dp.. but nothings works. I work with the emulator.
AndroidTv 1080p API 25, RĂ©solution 1920*1080:xhdpi
Nexus 5 API 24 RĂ©solution 1080*1920:xxhdpi
Nexus 7 1200*1920 xhdpi
Thanks for your help !
The documentation you want is here: https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
The important parts of this page are Table 2 (configuration qualifier names) and the section titled How Android Finds the Best-matching Resource.
Reading these, it is clear that you will use the Smallest width qualifier to differentiate between phone and tablet devices, and the UI mode to differentiate between televisions and non-televisions. This directory structure should work:
res/
layout/
layout.xml (default (i.e. phones))
layout-sw600dp/
layout.xml (non-televisions 600dp or wider (i.e. tablets))
layout-sw600dp-television/
layout.xml (televisions 600dp or wider)
Because the Smallest width qualifier has a higher precedence than the UI mode qualifier, if you tried to just use layout-television you would find that your TV still used the -sw600dp layout.

Is it necessary to create "small, normal, large and xlarge android xml layouts" folders if i want my application to run of all Android devices

I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.

Providing layout resource for Nexus4/Nexus7 against NexusOne/NexusS

I want to provide 2 different layouts for these 4 devices. I want Nexus4 (1280x720) and Nexus7(1024x600) use layoutA and NexusOne/NexusS (both 800x480) to use LayoutB.
I read the developer guide and still cannot figure out what kind of qualification I should specify to the different layout folders in "/res".
What's more, I even want the NexusOne/NexusS to use layoutA in portrait mode and layoutB in landscape mode.
In a summary, the threshold of the difference is the width and the density of the screen. I want to:
w>480dp use layoutA
w<480dp use layoutB
Can I achieve these goals at the same time?
Take a look at the docs - http://developer.android.com/guide/topics/resources/providing-resources.html
For N4/N7 have the resource directories
layout-sw600/layoutA
For N1/NS have the resource directories
layout/layoutB
Taking into consideration landscape and horizontal layouts, have an additional directory for N1/NS alone.
N1/NS
layout-port/layoutA
It's wall written in the tutorial. The folders you want are:
/res/layout-sw480 with layout A
/res/layout-land-sw480 with layout B
/res/layout-land-sw720 with tablet and nexus4 layout
Thanks for the gentlemen's answers above. I have tried many combinations of the qualifications and finally figured out the correct one:
/layout - small layout for short width as N1/NS-port, QVGA-port
/layout-w360dp - big layout for large screens N4/N7, and for landscape mode of N1/NS and QVGA
/layout-land - same as above
This works fine for me. The trick here is that QVGA is ldpi, N7 is mdpi, N1/NS is hdpi, N4/GN is xhdpi. I haven't tried it on a screen smaller than 320x480

android multiple screens compatibility

I read info about "Supporting Multiple Screens" and other post here... but Im really confused about how can I develop my application that run on multipple devices.
I was starting develop on a determinate screen (normal size layout), then I run my apk on a S4 galaxy so I see that every object of my apk was diferent size to my xperia to the S4.
what I need to do to make my apk compatibility for all the devices?
I read information that the only source to make that is:
res/layout/my_layout.xml // layout for normal screen size
("default")
res/layout-small/my_layout.xml // layout for small
screen size
res/layout-large/my_layout.xml // layout for large
screen size
res/layout-xlarge/my_layout.xml // layout for extra
large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra
large in landscape orientation
For:
res/drawable-mdpi/my_icon.png // bitmap for
medium density
res/drawable-hdpi/my_icon.png // bitmap for high
density
res/drawable-xhdpi/my_icon.png // bitmap for
extra high density
is this true? so I need to make different layouts for different devices?
guys please help me with this issue cz I relly dont understand how is the deal for multiple devices compatibility.
For the layouts:
You can most likely get away with one set of layouts for your application. By default, Android's gui system is done in such a way that you should be able to make good use of the screen of any device, for example use layout_weight and specify things in dp (density-independent pixels). By providing only one layout though, you're most likely going to have it optimized for phone or tablet sized screens. If you create it for phones, then tablets will probably have a lot of empty space, whereas creating another set of layouts would allow you to put extra info on the screen than the phone layouts could fit. It depends how willing you are to customize your app experience for each users device. To create multiple layout, it's recommended to use the Android 3.2 size qualifiers. For tablets, you could use res/layout-sw600dp. See here under "Using new size qualifiers".
For the drawables:
You will most likely not want to have just one set of drawables. You can, and the Android system will scale all your drawables to maintain the same physical size on all screen sizes, but due to scaling, the images will not look very good. That's why you provide an image that will look good for each "category" of screen density, and the Android system will choose the one for that device's screen density, and any scaling it has to do will be minimal.
It is kind of confusing at first, but you most likely don't have to worry about the layouts specifiers just yet. I would make sure to read the supporting multiple screens article and writing your xml layouts such that they make use of the screen size in a relative way.
Have you read this page? Or this one?
You create resources with duplicate names located in folders that are qualified a certain way. At runtime, the system will choose the resources that best match the current configuration of the device. If you want your device to work on multiple screen sizes and multiple screen densities, you will need to create different resources (layouts, drawables, etc) and qualify them appropriately.

Android Text Scaling on different resolutions same density

I have 2 devices, a 1024x600 7" tablet hdpi running Gingerbread and a hub attached to a touchscreen which is 1920x1008 22" in size, hdpi running ICS. The Android OS seems to consider both as "large" (240dp).
So, they have the same actual density (240dpi), same generalized density (hdpi), same generalized size (large) but different actual size (7" vs 22")
The text and spacing dimensions that I specify for my layout work great on the 22", but then on the 7" they look enormous and dont fit on the screen.
I've tried using dp and sp, no difference as I think the problem is that Android sees these things as the same size / density. Does anyone have any recommendations on how I can be able to scale sizes appropriately?
This program wil also eventually need to be supported on a 4.5" handheld as well.
Thanks in advance.
Sorry, my previous answer was completely wrong = )
Ideally, you should be able to design for the 7" tablet and have your layout scale up to the TV. But if that doesn't work you should be able to use something like layout-sw1008dp. The "sw" prefix allows you to specify the minimum dimension of the smallest side of the screen - so in the case of a TV, the height.
I am also facing such problem in my application. But i found a good solution for this.
I have only one layout for tablet and directory name is layout-sw600dp.
Now, when part came to height and width problems, I have created several different values directory in which i place dimensions and font size and other stubs. So there will be no constant value in layout of tablet screen.
androd:layout_width:"60dp" // i drop this scenario
androd:layout_width:"#dimen/tab_width" // i used this scenario
and your values directory name will be like
values-xlarge
values-large
All the values will be fetched from your values directory. It will not create different layout, but one layout can be used multiple times.
See my stack answer which may help you.

Categories

Resources