simply scale up phone xml layout for tablets - android

I designed my app for phone. If all I want for it on Tablet is just to scale up everything (i.e. bigger images, more distances), Is there a way to ensure this happen when doing my XML (or in the code)? Or should I create a different xml for xlarge screens?
I always come across the question and don't know the answer. Please don't refer me to the documentation of supporting multiple screens because I read it many time and it shows how you can customize for diff screen sized. In my case, I just simply everything scaled up keeping the same ration as the phone
Thank you

Related

Android App XML multiple screen support

I made a calculator app and used density independent pixels to create the layout, place the buttons and so on. Yet on a tablet emulator it doesnt display correctly, it only takes about 1/4 of the screen. On my phone(800x480) everything is ok. How can I adress this issue?
You'll need to provide additional layout folders for the different screen sizes so that the Android system doesn't use the same one by default, resulting in the behavior you've described.
This is accomplished by adding layout folders with size specifiers such as: small, medium, large and xlarge.
layout-small is an example.
So, to be clear, you're adding additional folders for the different supported screen sizes. You'll then add a layout of the same name to each folder you add. The system handles the headache.
You would then alter the layout to achieve the best results. Note that it is common practice, when dealing with larger screen sizes, to provide more content on a single screen as opposed to blowing everything up. If your app can benefit from that, it looks better than having obscenely large buttons stringing across the screen, IMHO.
For a complete run down, please refer to Android Documentation.

Supporting multiple screens in Android for numerous activities and resources

I have around 10 activities in an app and around more than hundred images. Now need to provide support for multiple screens of diff sizes and densities. If I need to create for small,large and xlarge sizes even though it will be customization of 30 more activities rest aside diff densities for a specific size :O Is there any way I can stretch the whole layout depending on the size and densities, I mean what is the best way to solve this problem. It must be a very common problem but I am missing something here. I read the android dev. screen support doc but still confused. Any ideas? Thanks for your help.
It's hard to give an answer specific to your project, but in general Android does a good job of this all by itself. All layouts will automatically scale if you haven't specified fixed dimensions (ie using px instead of dp). When it comes to fullscreen images (background and the like) it is best if you provide several resolutions (in the drawable-mdpi, drawable-hdpi etc) folders. You may also have to look at the scaleType for an ImageViews you may have.
Read through the official documentation on how to support multiple screen resolutions. It provides all the information you need and it goes into detail on how to provide different layouts not only for different screen resolutions, but also for different screen orientations and things like smallest width etc (for tablet specific layouts)

Screen Compatibility

I have developed an Application for android compatible devices mostly covered mobile phones, but when I am running it on Tab the screen size will get changed and all the content on the particular screen not behaving properly, As I have designed it keeping in mind that it should be compatible with mobile phones
Now, I just wanted to run my app on tab with the same screen size as it is showing on my mobile phone, without stretching of screen size.
What should I do to achieve it ??
Thanks
This isn't really a question that can be answered with a simple "set this style flag on your activity and you'll be on your way!" kind of answer. To get an app to scale properly across multiple screen sizes, you really need to start with the layout design itself. Android will try to keep your components the same size across different screen densities, but if you just leave it at that it still won't look very good because you'll have lots of empty or poorly utilized space.
The platform documentation and design guidelines go fairly in-depth into screen size compatibility and making a single app work and look good across all screens, large and small. In particular, I recommend reading the following articles:
Supporting Multiple Screens
Supporting Different Screen Sizes
Supporting Different Screen Densities
It'll take some work to make your app look and work great on tablets and phones (with just one APK) but if you want to make a good experience on a tablet without the hassle of maintaining two separate codebases, it's worth learning.
Pay particular attention to size qualifiers, which allow you to load different resources (drawables, layouts, etc) based on screen size (small, medium, large, x-large). That way you don't have to just blindly scale everything up on a tablet... if appropriate, you can tweak your layout on a tablet to make the experience more user-friendly.
Additionally, I recommend looking into Fragments, which allow for lots of flexibility in your UI across tablets and phones while not requiring you to have to write a bunch of code for differing layouts. For example, instead of having a newsreader that has two screens, one to display a list of articles and one to display article content, you can use Fragments to have a side-by-side, two-pane view of articles and content on tablets, while still having two separate screens on phones, which are more narrow. Fragments and FragmentActivities make this much easier to write and maintain.
You could set layouts width and height in pixels.
It probably isn't the only way but it's what comes to my mind right now.

android screen resolutions and sizes

I am currently working on an android app that is causing me some trouble. My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on. Unfortunately things like the FWVGA/WVGA resolution difference 854 vs 800 is causing me some real problems, and that's aside from the other sizes/densieites and resolutions.
I don't know if I'm just missing the point here but how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?
There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.
I have tried using displaymetrics but unless i have my manifest claim that it supports all screen sizes, the android OS will in fact "lie" to my app about hte current resolution.
Someone please tell me there is an easy solution.
how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?
IMHO, you start by revisiting your GUI design:
My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on.
That does not work particularly well anywhere, IMHO. Windows (including browsers) can be sized to any desired size by the user, for example.
There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.
Because Android devices can have any number of screen dimensions, just like windows and Web browsers can have any number of screen dimensions. Android does let you choose images based on density (e.g., -hdpi) or screen size (e.g., -large), but these do not map to resolutions, nor should they.
As CommonsWare pointed out, your best bet for this situation really is to rethink your layout structure. It's probably possible to accomplish similar, if not identical results to what you currently have, using RelativeLayouts and widgets. If you're willing to post a sample, we could advise you on ways to do so.
That said, an answer to your question would be to query the device at runtime for its screen resolution (keeping in mind space taken up by the notification bar, as well as the title bar - unless you theme it without a title bar). You would need a different image for every possible screen resolution, and as more devices (notably tablets) begin to release, you're going to have to continue to provide more images and customized code for each different image as they release. You can see why this is not an ideal situation.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels();
int screenHeight = metrics.heightPixels();
Then you can place that into an if-then-else block, and determine the resolution, and set the image accordingly. I don't recommend this.
When it comes to displays and resolutions, it is not possible to have your images resized to any aspect ratio without either squishing / stretching them, or using letterboxes. I know this doesn't really answer you question, but if you can't get reliable screen size information from the OS, then try picking images for the largest resolution and cropping them for the smaller resolutions. Just make sure there is nothing interesting around the borders.

From .psd to screen

I have a client that gave me a .psd file that contains the entire screen of an Activity with all the graphics. The resolution is 480x800. The client wants the application to look identical to the one in the .psd file. The problem is that different devices have different resolutions and sizes. I know that the density is what really matters but how can I scale the graphics to look the same on all the devices? For example, I exported all the layers and recreated the screen in Android but, for some reason, the screen looks more crowded on a Nexus One (480x800).
One idea would be to create 9 patch images from the graphics and use for ImageViews android:background instead of android:src right?
Isn't it better to have a 320x480 resolution for the graphics? Or do I need for both resolutions? Also, I have to consider the height of the status bar which I understood it is 25dip but I am not certain about this.
So, to summarize, I am interested to find out what is the best way for a client to give you the mockups and graphics so that it is easy for the developer to implement according to the specifications.
That's something that's not easy to solve. Think of a webdesigner, one can't know all the possible resolutions and settings of every browser so he has to scale things accordingly.
In my opinion there are only three approaches here.
First: Let him state what devices he wants to support and only support those devices. Extract the layers with the size of the device with the highest resolution and scale them down on other devices.
E.g. If you have to support two devices with 480x800(2) and 240x300(1), export all images to be 480x800 and scale them down accordingly. Don't write a single application for every device.
Second: Export the graphics with the highest resolution possible and scale them down on all devices relative to the device being used. Imagine, again, a webdesigner. All he does is define margins, paddings, etc. and it will look nice in almost any browser. You should do the same and resize your elements on demand.
Third: Make the application fixed, e.g. define a size of 200x200 for your whole application and just fill everything larger than the screen with a certain color, e.g. black. This happens a lot with java ME applications, they look great on the hardware they were made for and are still playable on hardware that is beyond their time though they look pretty ugly.
Hope this helps,
Robin.

Categories

Resources