The answer to this may be, 'you poorly designed your app', which is likely as I'm still pretty new to this.
Issue: I have small game that I created where the background image of the screen is the game board. On it, are locations for scoreboards (part of the image). I am using textviews as the different scores that will display on 4 score boards. My issue that I am trying to address is keeping the textviews placed where I need them, directly over the score board images, when different size and density devices are used. (things move around).
I have this working great on many different devices and densities using multiple resource qualifiers on my values folders. For examples...
sw320dp-xhdpi
sw400dp-mdpi
etc.
I am running in to situations where I have two devices that are both xhdpi and their resolutions are very close.
device 1: 1280 x 720
device 2: 1280 x 768
As I have things currently, this will result in both of them using the same dimens file that is being used to place the text views. Ultimately, this results in one of them aligning things perfectly and the other being slightly off.
Is there a way handle one of them uniquely via a 3rd resource qualifier?
Is there a different way to handle this outside of resource qualifiers?
Did I approach this poorly and there is a much cleaner way to handle what I am trying to do?
Thanks,
Bob
This may not be the in-depth answer you're looking for, but Google announced their new version of Android Studio a while back. It includes the ability to make one layout fit all devices. Check it out:
Related
I am relatively new to react native and am not looking for actual code however I am wondering the best way to implement layouts/ styling of a page so that it looks the same proportion wise across multiple different devices and operating systems. For example iPhone X through to 13 have different size screens and then if you include the new Samsung's, Google Pixels and Huawei phones there is a lot of different sizes of screens.
I can create different styles by detecting what device is being used and getting the logical resolution from that however I am wondering if there is a better way than just doing this for 10 different phone sizes. For example in the picture you can see the front wheel of the car is on the edge of the blue box which gives it an almost 3D effect.[] To get this effect across 2 different devices I have to change the absolute positioning of the car for both devices however the more screen sizes/ devices I want it to look the same on the more code it is and it seems like I am using a long winded/ redundant method.
Another alternative I have thought about is just turning that section into an image and using it as a background image however I am not sure how that will affect performance.
Any thoughts?
How is someone supposed to use the drawables located in ...\AppData\Local\Android\android-sdk\platforms\android-22\data\res in Android Studio projects?
For example, if someone would like to change the Floating Action Button icon to a pencil icon, what is the standard practice?
Is there some kind of documentation available that demonstrates what each drawable XML file actually looks like when drawn? Or are you expected to copy and paste these into your project in order to see what they actually draw?
Surely there is some kind of gallery somewhere...
Unlike any other O.S, Android powers billion devices with different screen sizes, ranging from small phones to large TV sets. And it becomes a primary necessity to run apps with perfect User Experience on all sorts of devices! And for that purpose Android uses DIP or DP (Display Independent Pixels).
And coming to the solution to your question, consider reading from here
And, the general procedure is to generate images of different resolutions for different screen sizes, see this
Also, this video explains it simple!
And in order to generate multiple images with different resolutions for the respective screen sizes, I personally use a resizer tool. Final Android resizer, available here.
hope it helps!
After some years of Android development, i took months wondering why should i use xml layouts to make the UI of my Android App.
I understand that part of MVC and real-time graphical interface design.
If im wrong please take me out of ignorance and forgive me but , I´m Unable to set a view´s position, exactly, 8% of screen width for margin and 70% of screen width for width, for example.
Creating the UI in that way and taking care of screen aspect ratio ensures the app will look proportionally exactly the same in all devices.
As this post sums it up, we are told to use dip units and a nice bunch of xml files for every layout of our app if we want to support different screens. (Why they call it density-independent if we have to make it different for each screen density?)
But, even doing that, as (again) the Google Doc says
The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion.
And in place of not necessarily they should say mostly never looking at the incredible number of different devices. Depending of your project, this may be a problem. (Or do you want your client looking at your "slightly-decomposed" UI on a who knows chinese device)
I could ask the same for the image resources, but that whould be another question, i use to put the highest resolution on -nodpi then downscale by code to screen-width-dependent desired size, instead of putting 10.000 images at all resolutions.
Creating the UI in that way and taking care of screen aspect ratio
ensures the app will look proportionally exactly the same in all
devices.
This is the way Apple does it, and this why when you open a folder on a 9.7 inch iPad with beautiful retina display, it only displays 9 icons.
A tablet is not just a bigger phone. It's really not. Also, iOS devices have mostly the same aspect ratio, so that's how they took care of the aspect ratio.
On Android however, you can't just say that you "took care of the aspect ratio" problem and that this problem magically goes away. Your best bet is to use Android best practices to handle aspect ratios correctly.
That being said, don't over do it either. You don't need to use all 8 density buckets for instance. Look at the official dashboard to see what devices people are actually using, before you try to optimize for every scenario possible.
Also, you don't have to listen to Google all the time. For instance, I am sure that Google would love that you translate your application so that it's available in more then 68+ different languages worldwide, but what's good for Google is not necessarily good for you. Android actually lets you choose the tools you want to use to make your application. They don't force you to use any particular one.
Actually I need some suggestion like Designing screens for android mobile as well as tablet. As of now im creating two different folder for xml one is for mobile and another one is for tablet. Im placing images in 4 different images with 4 different resolution like (160 dpi, 240 dpi, etc). so am i going in right way or i need to change the way of designing. Thanks.
When designing for different devices it is important to test whether there is a necessity to create different layout files for the different devices. If you find that you do want that then there is plenty documentation online about it. Read these first:
Designing for different screen sizes
Guide lines
More android screen size documentation
Each of these links explain the new methodology of designing for multiple screen sizes.
A few tips on top of the already answered question that I gained by experience:
Use #dimen everywhere you have to specify a width/height but in general, avoid specifying them if you can. This way, you can override the dimension based on the available DPI and don't have to replicate your layouts.
Use LinearLayout wherever you can and use weights to determine how things should be drawn. Other layouts like relative layout are fine as long as they're used for positioning (isLeftOf for instance) as opposed to making a certain space available.
Use fragments wherever you can. It's much easier to work with self contained fragments. In general, avoid having any UI logic in your activities and let the fragments handle them.
Use the Android Asset Studio (http://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html#source.space.trim=1&source.space.pad=0&name=ic_action_example&theme=light&color=33b5e5%2C60) which will take care of resizing your images for you. It's been very valuable to me. Have a look at these other projects too. They can help you in many aspects when designing your UI: http://romannurik.github.io/AndroidAssetStudio/
Even when you do all this, you may come across a scenario where you really do need to write a different layout for tablet and phone. If this is the case, as long as you've created everything in self contained fragments, it's much easier to switch fragments or even use the same fragment code with different layouts (as long as they contain the same UI elements) depending on the dimension. It would also be advisable to use the trick here (Determine if the device is a smartphone or tablet?) to determine if you're running on a large/small tablet or a large/small phone.
All in all, it's a little bit painful developing and testing your app on all the available device sizes but as long as you follow the above points, you'll have an easier time.
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.