Override res folder determination - android

So, I'm making an app that has many different res folders for values, drawables and layouts.
The variation is by screen size, mobile country code (I'm using this field to override it and thus enable different skins in my app, much like iOS targets), landscape / portrait, screen widths, languages & dpi.
One of my biggest problems for this app is the fact that I need to support both tablets & phones. I create a layout for phones under layout-normal. If I do this, it seems like I must copy-paste my tablet layout into both the layout-large & layout-xlarge folders. If I don't, the app defaults to the normal layout.
I was wondering if there was a way in Android to override the way the runtime determines which folder it goes to. This way, I could via code, direct the run-time to the correct folder depending on the device's configuration, and not need to copy-paste my layouts all over the place.
Note:
I specified 1 reason I want to do this, but there are also several others. I'm looking for a way to override the way android determines which res folder it goes to, not a different solution to the 1 problem I specified above.
Any advice would be greatly appreciated!

In order to avoid the duplication you could use the resource alias mechanism as described here. That system can be used for images, layouts and other resources from the values folder.

Selection is done based on device configuration as explained here so if you could find a way to alter device configuration then it will work. But it will effect other apps as well. There are apps that allow you to change your device modes. There are custom ROMS that give this ability e.g. Paranoid ROM

Related

PercentRelativeLayout for same screen on Android phone and Tablet?

The screens in my app needs to be displayed in the same way on both type of devices, phones and tablets. Currently my app works fine on phones, but they behave weird when run on tablets. The problem occurs with the positioning and size of components in the screen.I have 9 patch images generated for all the images being used but still for some components that I use absolute size/margin values such as 30dp,50dp etc do not seem to be good measures that work well on a tablet. Some of my thoughts/questions are:
PercentRelativeLayout - is it the best solution to overcome this
problem?
Is there a way that layouts can be defined so as to draw
differently on phones and tablets. Please note that that I do not
have any complex menus or behaviour that needs to work differently
on different devices, they are same.
Do I have to develop 2 different apps?
you have to make different layouts for both android phone and tablet.
Look at this link
Read more on the Android developer documentation after reading answers above. Found this resource to be more explicit for someone who is totally unaware of supporting multiple screens. http://www.survivingwithandroid.com/2012/07/how-to-support-multiple-screen-in.html

Android Device compatibility issue in Normal Device

i am suffering from last few days but i am not getting any perfect answer for that
android developer website
i
and apart from that i am also study lot of website but most of the website say's use dimen and used it for
small
normal
large
and x-large
but it is not giving me the perfect solution because most of the device which i am testing they all target normal dime such like that device start from 3.7 to 5 inch and because of that my card get moved up according to device i want the perfect appearance on each device there is a image attached to it
actually i want the perfect apperance on each device i found one method which is work fine to make a dimens xml according to the dimension of screen but it is not reliable i have to make more then 25 xml and if another device will come i have to make for these also this is image Url
If you want to support all devices then I think under my opinion You need make a check up on several points. These points are given below:
first you should make it sure that you are using right sizes in all drawable bucket. I am saying this because I think You are looking it perfect in some device but not looking good in other devices.
Do not make multiple xmls it is deprecated.
TO give margins for all devices you need to make different values folder or Dimens folder for different devices.
This is new way of supporting multiple devices , multiple xml is deprecated.
Here I am posting 2 links , this and this , check them out. I think that this is good for you to learn , just give it a try. And Up vote if this helps.

Program different layouts for different versions in android

I have to program my Android app with the best compatibility to different screen sizes (tablets and smartphones) and to the versions 2.3, 3.2 and 4.0.
I know about the possibliy to name the folders of the layout like res/layout-sw600dp/. to match the layout exactly to different screen sizes.
So, cause I will use completely different layouts for Tablets / Smartphones, I would start with a "Load Screen", which tests which Android-version is used and if there is used a tablet-or smartphone-device, cause for example in the layout for the Tablet, there will be Buttons on some screens that won't be there on the smartphone.
So I will have to separate all this in packages, like this:
Common
2.3
Tablet
Smartphone
3.2
Tablet
Smartphone
4.0
Tablet
Smartphone
I would choose this separation, cause it's the best way, in my opinion, to be prepared for upcoming *updates*, if, let's say there should be added a Button in the ToolBar in Android 4.0.
Is this separation a good thing in your opinion or is this a complete overload?
Are there any other new features in 4.0 that I should be aware of?
You can also name your resource folders to indicate version number (like /res/layout-v11) or (/res/values-v13)
Regarding your question about separation - it really depends on your particular requirement. A common approach to this problem is a fall-back mechanism: You provide a few specific layouts (for example, an xlarge landscape v11 layout), and a few generic ones to fall back to.
Of course, this is an "idealistic" solution; and it doesn't always work that way. In other words, it is mighty difficult to practically implement an app that is compatible with so many versions of Android solely by providing alternative resources. Even if you use the compatibility libraries (which helps a bit in reducing version-specific code); you will still have to adapt your code based on the version at run-time.
You can find out the Android version looking at Build.VERSION.
The documentation recommends you check Build.VERSION.SDK_INT against the values in Build.VERSION_CODES.
And based on that version you can set your layouts in if else conditions

Android phone and Tablet problem

I know this is not a technical related question.But i do not have any idea.I am going to develop a project which should be supported in both phone and tablet.Is it possible having one project working for both tablet and phone ?
Yes. The only thing you need to keep in mind where you keep your graphics. Because it will cause different problems if you do not treat and handle them depending on the screen size. Only thing matters is the android version. If you deploy your app in any phone or a tablet where the version is newer or equal to the target version it works. But of course you cant take a call or some other mobile functionality from a tablet if its not supporting that features.
You can use drawable-hdpi,drawable-mdpi and drawable-ldpi for the graphics(images which use in project) and also use layout with multiple screen by custom layout like layout-480x320 , layout-600x1024 etc. in layout you can custom screen xml file.

How do I ensure my android app will look the same on all android phones?

Is there a truefire way to make sure my app will display the same on my Motorola Droid 2 as it will on other Androids?
I use nothing more than basic Linear Layouts, Image Views, Buttons etc - is there a good checklist to go by before I even think about launching an app?
Clipping issues, What SDK I should launch my app in, etc...?
Make sure you are following the guidelines for supporting multiple screen sizes.
You can use the emulator to experiment with the different possible screen sizes and densities, as described in that document under how to test your app.
You can make emulator of different screen sizes to check your application.
One thing make sure you don't use "px"(pixels) anywhere in your application, use dp instead of px.

Categories

Resources