android- How to Support Multiple screens - android

I implemented the application which supports different normal screens. For this, i created the 3 folders(like layout-normal-ldpi,layout-normal-mdpi,layout-normal-hdpi) in the res folder. In this i placed the different xml files with same name.But i got android.content.res.Resources$NotFoundException. How to handle this? can anybody help me.
thanks.

The folder your created are incorrect refer to below ones
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
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
Below is pic for res folder structure for more simplicity

I think the 'normal' and 'dpi' are redundant.
I guess you already looked here but maybe should review it again.

Related

How does android choose the right layout/drawable for the correct screen resolution?

I that When starting an android application, android makes a good "guess" as to which layout/drawable to use depending on the screen size. However, I was wondering where it chooses this from? I ask this because I have quite a few layouts which don't all work. I read on the android website that you can make a folder called layout-xhdpi, layout-ldpi... etc. But does android automatically look for layout-xhdpi or layout-ldpi or do I need to specify that anywhere?
Same goes for drawables. When creating a new application in Eclispe it makes automatically drawables folders for you but does this necessarily mean it looks for those.
Conclusion:
Where does android look for alternative screen sizes and how/where can I change that?
Create following layout folder
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
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

android -notlong eclipse: "Invalid resource directory name"

I try to refactor/rename my layout/large forlder to
layout-xlarge-mdpi-notlong
Then Eclipse return this error
Invalid resource directory name
I really don't understand why.
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
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
Supporting Multiple Screens
because -mdpi-notlong is not supported in android.
You can not rename the name of resource folders the way you want. Android keeps it standard. You should read this link.http://developer.android.com/guide/topics/resources/providing-resources.html

layout for multiple DPI and SIZE screens in android

how am i refer a layout in res library for differnt screens (DPI and SIZE)?
can i do this in re folder:
layout-mdpi-xlarge
layout-mdpi-normal
layout-xhdpi-large
and so on...
http://developer.android.com/guide/practices/screens_support.html
You can find an answer to your question by going through the link in detail.
See the topic under Using configuration qualifiers especially the section under table1.
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 drawables.
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

Override layout of "layout" folder for normal screen device

I implemented all layout files for hdpi devices. And put them in "layout" forder. Now I tested on a normal-screen device, and there's some screen I urgently need to change, because a required input field doesn't appear (because of the small screen).
What I did is create a folder called "layout-normal" and put there a copy of my layout file, and reduce in the copy everything a bit so it fits the screen. Now I have 2 problems and don't understand anything.
Both files point to the same source - when I open them I don't get 2 files, but only 1 with my modifications.
Ran this on the normal-screen device and it still looks like at the beginning.
Please help :/
layout-normal and just layout are the same. It is just the default layout
Ref: android developers site
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
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
..
Size 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 build Layout for all device

it is possible to build layout (ex: menu)
that will use coordinates system pt
I need to build menu for game and I need to set all fields on same positions on every screen size
if screen will be big it must be scale everything on the layout and same on small screen size
like this:
can you provide some example for it?
The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.
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
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
This has been taken from http://developer.android.com/guide/practices/screens_support.html
If you sort your xml files this way, Android itself figures out what file to choose depending on the screen size of the device.
While designing the desired layout, you can opt for Relative Layout which usually sticks to its attributes such as alignParentBottom, alignParentTop, alignParentRight, alignParentLeft to name a few.
I hope this solves your issue, although I'm not clear what you're talking about when you say "coordinates system pt"
create the image with 9-patch so no need to save the images for different density like hdpi,mdpi etc. it will adjust with control as you define the size or you can save images with different size into the hdpi, mpdi with same name and by runtime in device it will get the appropriate images as per the density available
edit
links for 9-patch
http://developer.android.com/guide/developing/tools/draw9patch.html
http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial
http://www.androiddom.com/2011/05/android-9-patch-image-tutorial.html

Categories

Resources