I have a small Android app which works fine on resolutions up to WVGA (480x800), however beyond this the layouts don't scale (for instance for the Galaxy TAB 1024x600) but appear in the top in the middle (with black borders down sides and at bottom). The layouts look fine in Eclipse at these resolutions.
What Am I doing wrong?
Am I missing something in the manifest? Do I need to supply high resolution resources?
Try putting this in your manifest.
<supports-screens android:xlargeScreens="true" />
http://developer.android.com/guide/topics/manifest/supports-screens-element.html#xlarge
putting
<uses-sdk android:minSdkVersion="4" />
In the correct place in my manifest solved the issue. For some reason I had placed it under <application>.
I've created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html
Basically, defining your layouts in dp units is not enough if you want your app to fit on all devices and tablets, since there's 4 different "density-buckets". The tool will allow your layouts to be converted into fitting these density buckets.
It will also explain in further detail how to make flexible view components.
Related
I'm starting just starting out in android development. My IDE is Android Studio and I'm currently building my own calculator app. I used Nexus 5X
's screen which is 5.7":
My app using the 5.7 screen
The only problem I encountered is that when I tried to my friend's phone which has a 4.7 screen, it somewhat looks like this:
My app using the 4.7 screen
I thought that it the app would automatically scale everything just like when you're using viewport on web development. I'm a web-developer (html, php, javascript, css) and I'm planning to migrate to android development for ease-of-use. Is there any way to fix this without re-designing everything again guys?
Thanks, and peace out.
Android devices come in a variety of screen sizes and resolutions. That’s why handling the multiple screen size in android is most important.
Look into this: https://stuff.mit.edu/afs/sipb/project/android/docs/guide/practices/screens_support.html
Actual physical size, measured as the screen’s diagonal.For simplicity, Android groups has four generalized sizes: small, normal, large, and extra large.
To set up support for multiple device sizes in Android, add the element into the AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest ..>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>
<application... >
….
</application>
</manifest>
As we design our UI for different screen sizes, we’ll discover that each design requires a minimum amount of space.
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
We can also define it on the basis of dp like :
res/layout/main_activity.xml // For handsets
res/layout-sw600dp/main_activity.xml // For 7” tablets(600x1024 mdpi).600dp wide and bigger.
res/layout-sw720dp/main_activity.xml // For 10” tablets (720x1280 mdpi).720dp wide and bigger.
Steps to create Different Screen Layouts :
Step 1 : First go to Android to Project mode in Android studio change at below of the project name.
Step 2 : Create Folders for all screen sizes.
Step 3 : create same xml layout on all these folders.
For Screen Compatibility Issues Try to Use Relative Layout & with Scroll View So To Make your app compatible to Tablet & Horizontal Layout.
I had the same issue and I used this library and it did the thing for me.
The thing is you just have to replace sp with ssp in your xml after adding this library in your gradle and you'll be good to go.
Also for width and height I used this library.
Just replace dp scales with sdp.
I've also answered a question like this here aswel, have a look.
So I used the following code below to have my application to scale screen size on different android devices but when I am testing on my Nexus 7 its does not scale and its as if it was on a 4 inch screen. When I run it in the emulator on a 7 inch screen it works. Anything wrong with my manifest file?
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"
/>
this code goes right before the "application" part right?
Ok, so what you have to know is that support-screens doesn't make your application look 'nice' on screens you are supporting (check this link). It just tells that users with such screens will be able to download your application, but it's up to you to make it display properly. You have to create layouts for specific screens on your own.
More about it you can read in Android's documentation: http://developer.android.com/guide/practices/screens_support.html
Basically, you have to properly name your directories in which layout files are stored in order to let Android know which one should it pick up for specific device. If for example your layout's file was "layout.xml" you should have:
/res/layout/layout.xml // Default layout
/res/layout-small/layout.xml // Small screens
/res/layout-large/layout.xml // Large screens
/res/layout-xlarge/layout.xml // Extra large screens
You can go even further and make also different layouts for portrait and landscape views by specyfing another keyword in directory's name:
/res/layout-small-land/layout.xml // Small screens, landscape view
/res/layout-small-portrait/layout.xml // Small screens, portrait view
Remember that tags order is important, so you can't write layout-portrait-small.
Use Relative layout it will solve most of your problem .Additional use Folder name with given below
the way i am dealing with multiple screen is this way and its working fine.....if any one has improved wayso do guide me
Screen size 480x800
layout-normal-hdpi-480x800
drawable-normal-hdpi-480x800
Screen size Galaxy Nexus--- though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs
layout-normal-xhdpi
drawable-normal-xhdpi
Screen size Note 5.3---
layout-normal-xhdpi-1280x800
drawable-normal-xhdpi-1280x800
Screen size S3---
layout-normal-xhdpi-1280x720
drawable-normal-xhdpi-1280x720
Screen size 7inch tab 2 supporting OS version 3 and above--- dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs
layout-large-mdpi
drawable-large-mdpi
Screen size 7inch tab p1000 etc supoorting os verion less than 3---
layout-large-hdpi-1024x600
drawable-large-hdpi-1024x600
Screen size 1280x800 tab 10.1,10.2,note 10.1 etc--- you can add dimension if you want other wise it is fine
layout-xlarge-mdpi
drawable-xlarge-mdpi
So I used the following code below to have my application to scale screen size on different android devices but when I am testing on my Nexus 7 its does not scale and its as if it was on a 4 inch screen. When I run it in the emulator on a 7 inch screen it works. Anything wrong with my manifest file?
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"
/>
this code goes right before the "application" part right?
Ok, so what you have to know is that support-screens doesn't make your application look 'nice' on screens you are supporting (check this link). It just tells that users with such screens will be able to download your application, but it's up to you to make it display properly. You have to create layouts for specific screens on your own.
More about it you can read in Android's documentation: http://developer.android.com/guide/practices/screens_support.html
Basically, you have to properly name your directories in which layout files are stored in order to let Android know which one should it pick up for specific device. If for example your layout's file was "layout.xml" you should have:
/res/layout/layout.xml // Default layout
/res/layout-small/layout.xml // Small screens
/res/layout-large/layout.xml // Large screens
/res/layout-xlarge/layout.xml // Extra large screens
You can go even further and make also different layouts for portrait and landscape views by specyfing another keyword in directory's name:
/res/layout-small-land/layout.xml // Small screens, landscape view
/res/layout-small-portrait/layout.xml // Small screens, portrait view
Remember that tags order is important, so you can't write layout-portrait-small.
Use Relative layout it will solve most of your problem .Additional use Folder name with given below
the way i am dealing with multiple screen is this way and its working fine.....if any one has improved wayso do guide me
Screen size 480x800
layout-normal-hdpi-480x800
drawable-normal-hdpi-480x800
Screen size Galaxy Nexus--- though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs
layout-normal-xhdpi
drawable-normal-xhdpi
Screen size Note 5.3---
layout-normal-xhdpi-1280x800
drawable-normal-xhdpi-1280x800
Screen size S3---
layout-normal-xhdpi-1280x720
drawable-normal-xhdpi-1280x720
Screen size 7inch tab 2 supporting OS version 3 and above--- dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs
layout-large-mdpi
drawable-large-mdpi
Screen size 7inch tab p1000 etc supoorting os verion less than 3---
layout-large-hdpi-1024x600
drawable-large-hdpi-1024x600
Screen size 1280x800 tab 10.1,10.2,note 10.1 etc--- you can add dimension if you want other wise it is fine
layout-xlarge-mdpi
drawable-xlarge-mdpi
I'm using the Photostream example app to learn Android.
One thing I've noticed is that on my 800x480 4.0 phone the 6 photos in the grid fill the screen. However, on the 1024x768 pixel display of my 2.3 running touchpad they do not fill the screen, and are instead constrained to a tight grid towards the top-centre of the screen.
I want to adjust the app so it sizes itself appropriate to the screen size but I can't figure out why it's sizing the way it is.
Looking at the layouts in the res/ directory most of them specify fill_parent etc. The only explicit sizing I can see is the 150x128dip in grid_item_photo, but if I double this it seems to make no difference.
I tried changing the code in PhotostreamActivity.java to download SMALL instead of THUMBNAIL sized photos and it indeed seems to do that. However, it doesn't change the overall layout or sizing as they are cropped. This happens even with the above change.
I notice some sizing code in GridLayout.onMeasure() but this all seems to be driven by the existing size of the screen/widgets -- I don't see it enforcing an arbitrarily small size.
Another thing which occurred to me was that maybe it's to do with the resolution, but I don't see any hvga specific layouts or values in the res directory, just some overrides for landscape vs. portrait.
Why is the current code sizing things the way it does, and what is the best way to modify this so it works on physically larger, perhaps lower density screens?
I needed to add this to AndroidManifest.xml:
<supports-screens android:largeScreens="true" />
Apparently, it is not default on for all devices, unlike the other similar settings.
i created a game and released it, but really only tested it on phones and the emulator. later on i downloaded it on a touchpad and it confined to a small box at the top. through some searching i found that adding this code to my manifest:
android:resizeable="true"
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="false" />
i got it to fill up the whole screen, but everything is now horrendously out of proportion. is there a better way of going about this? do i need a separate layout xml for phones and touchpads? do i need to rewrite my original xml from the ground up?
Read this article:
http://developer.android.com/guide/practices/screens_support.html
By following the practices described in this document, you can create
an application that displays properly and provides an optimized user
experience on all supported screen configurations, using a single .apk
file.
...
Your application achieves "density independence" when it preserves
the physical size (from the user's point of view) of user interface
elements when displayed on screens with different densities.
Maintaining density independence is important because, without it, a
UI element (such as a button) appears physically larger on a low density
screen and smaller on a high density screen. Such density-related size
changes can cause problems in your application layout and usability.
...
The Android system helps your application achieve density independence
in two ways:
The system scales dp units as appropriate for the current screen density
The system scales drawable resources to the appropriate size, based on
the current screen density, if necessary
I think it is better to design your layout for every screen size and resolutions. It is easy in android. Copy your layout from "layout" folder of resources and paste it in the "layout-land", "layout-xlarge", "layout-xlarge-land" and ... folders and change those settings you need in them.
you can check this link: