Something is really wrong with Android.
I have one Device with a "Normal screen and MDPI" (LG Optimus 2X P990)
I have one Device with a "Normal scren and XHDPI" (Samsung Galaxy S3)
I try to have all layouts in one single folder, for all views. If I change the color/text/whatever on one view, it goes globally. To have that value such as a "Color" to be located in all different layout means I have to change all the files when changing something so rudimentary as a color, or textsize.
Then in each "values-normal, values-xhdpi, values-large" I have set all settings unique to that device.
Example "values-normal"
<dimen name="text_small">10sp</dimen>
Example "values-xhdpi":
<dimen name="text_small">4sp</dimen>
Example "values":
<dimen name="view_textview_title">#dimen/text_small</dimen>
Currently, the MDPI device doesn't load the values from the "Values" folder, only when added to "values-normal" and the XHDPI device doesn't load the "values-xhdpi" if there is a Normal folder.
Well, to say the least I can't optimize the App for two different devices. That's what wrong.
Cause, I read that the "Normal" folder overrides the "XHDPI" folder for a Normal screen device with XHDPI Density. But to be able to see the Title text I have to set the text on the XHDPI text size to something like "4sp" while on the Normal with MDPI it's about "10sp".
A higher density will multiply the value more, a lower - less. Am I right? Then this way there is no possible way to optimize an App for two different devices with just a Density change. Each screen size with it's density size needs it's text size.
So, my question is the following...
Can I combine "values-xhdpi-normal" "values-mdpi-normal", "values-hdpi-normal" and such?
Otherwise, I have to make the App ugly for some devices and look good on some. I like probably more like me, don't use "TextSize = 10" on the whole page. A title is a title, larger, a menu is a menu, smaller text, descriptions on a menu even smaller. There you go.
Reason I'm asking is because I don't wanna reset the current layout without it being possible, too much work for nothing otherwise and Eclipse is buggy enough with it's productive approach of having to add a single line just to force a reinstall when a library has changed or restart the whole environment for it to understand that something's changed - especially with Values!
Related
hi I'm new in android developing and it's my first app.
I have made these folders in address : app\src\main\res for supporting multiple phone and tablet screens and put proper dimens.xml files in them.
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
values-sw600dp
values-sw768dp
values-sw800dp
first of all, are they complete or am I missing some screen sizes?
second, I've tested the app on several devices and it's working fine and has proper user interface in all phones but on the Galaxy Grand Prime which has a 5 inch 540 x 960 pixels display that means 220 dpi. this phone using hdpi dimens but UI is a bit messy.
The following pictures may make my point better :
Proper UI , as it is shown in other devices
VS
UI in galaxy grand prime 220 dpi display
as UI is completely OK in other devices, I thought I should make a specific dimens.xml file for that kind of dpi, so I made values-sw220dp. but after that other phones used this dimens instead of hdpi dimens and problem got worse because UI was fine in the galaxy phone and was not proper in other hdpi displays. and now I don't know what should I do.
can anyone help me in this issue?
at last sorry because of flaws in my english , as you can guess I'm not a native.
are they complete or i'm missing some screen sizes?
If you read the guides which I mentioned at the end of my answer you will find that there are very many possibilities of defining resources folders. I think nobody will want to implement all of them.
Usually you look at your app and then decide on maybe three or four screen sizes you want to support. I think "sw220dp" is important, if only to show a message that your app needs more space :-).
So there could well be three to five layout folders (sw220dp, sw320dp, maybe sw480dp, sw600dp, maybe sw820dp). If you need orientation-dependent layouts, then the number will be twice that much. (Why ? That's explained very well in the guides linked below)
You already know that there are different types of resources. Some of them do not depend on the screen resolution (e.g. layout files), some do (drawable resources).
So first of all you decide which screen sizes you want to support. Let's say they are "phone", "tablet" and "220dp". You create three layout files by the same name "my_activity.xml" and put them in three folders
for the really small window: res/layout-sw220dp
for the mobile phone: res/layout-sw320dp
for the tablet: res/layout-sw600dp
By the way, "sw" stands for smallest width which is the minimum length of the screen, no matter what the orientation is currently.
Now let's assume you have created three different layout files and all of them contain an ImageView like this:
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/my_picture" />
This is where the screen resolution comes into play: 24dp is a size value in "density-independent pixels". It will be resolved depending on the screen resolution of the device. So you need different versions of my_picture.png, and for this you need different folders for drawables. They are named after the different categories for screen resolution so the runtime knows which png file to pick:
res/drawable/ldpi (although I read somewhere you can skip that because the pictures will be scaled down from hdpi nicely)
res/drawable (here go the resources for res/drawable-mdpi as well as every drawable resource for which resolution does not matter, e.g. drawables defined via xml files)
res/drawable-hdpi
res/drawable-xhdpi
res/drawable-xxhdpi
res/drawable-xxxhdpi
Helpful links:
Providing Resources
Supporting Multiple Screens
I am designing an app with a .jpeg background and with text views on particular places on the screen. I designed this for my nexus 6 and used dp for the widths and heights of text views and margin-left and margin-top. What my understanding of dp is that it changes with every device according to screen size and density. So it should work on different phones according to the value of dp for them.
But this is not the case. When I run that app on a different phone (nexus 5) the layout is all messed up. I tried using the different resources and qualifiers for different screens (large, small, normal). But the problem still prevails. The app considers both nexus 6 and nexus 5 as large screens. How do i fix this?
this is not the best solution i guess.
i guess your layout is just on the layout folder. i don't know if the first device you tested the layout is large or small but what you should do is create another folder named layout-sw600dp. this folder is used by tablets. the folder layout is used my phones and smaller devices. you could also create the layout-land and layout-sw600dp-land folders for the landscape orientation.
dp do change depending on the device but if your layout gets messed up then i guess the layout called by that device doesn't fit its resolution. i guess dp becomes smaller if the device is bigger and vice versa.
I am developing app.I have only layout folder with xml files,it is showing properly in more pixel screen ,but when i see my app in less pixel screen the text is big not same as more pixel screen As per android developer site, I came across layout-sw320dp ,layout-sw480dp. So I have added the xml files into layout-sw320dp,layout-480dp and made changes like text size and margin,then when i run them with sw-320dp in less pixel screen i can see text size same as more pixel screen,but when i run with sw-320dp the same in more pixel screen, the text is small ,it is taking layout from only sw320 actually it should take from layout folder.I d'not know where I am wrong can any one tell me.
screens with only layout folder
[![screen in less pixel density[![screen with more pixel][1]][1]][2]
screens with layout-sw320sp
[![screen in less pixel [![screen with more pixel density][3]][3]density][4]][4]
[1]: http://i.stack.imgur.com/6rTNw.png
[2]: http://i.stack.imgur.com/uHRkx.png
[3]: http://i.stack.imgur.com/qhcmk.png
[4]: http://i.stack.imgur.com/Z5PE0.png
You are not supposed to pick what resource size is shown, android does that depending on the device used at runtime. Your job is to set the resource in the correct folder for example res/layout/mylayout.xml and res/layout-sw480dp/mylayout.xml res/layout-sw320dp/mylayout.xml sw is smallest width of screen, 320 is a number, dp can be thought of as pixels. This concept of putting resources in folders with special names and allowing android to pick the most sutable special name/folder for the job works for any resource. Strings/languages, images/for device screen size,night/day,orientation-|.
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.
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.