I'm working with a few different ad networks, and they all work fine and dandy on most devices, but on devices with a high screen density, they try to be helpful and scale themselves up. But that's pretty much the opposite of what I need.
My layout is very specific to different screen sizes, and when I request ads with a specific pixel size from several different ad networks, they are scaled based on the screen density. My question is this:
How can I scale the views back down to the pixel size I asked for? If it helps, the ad networks I've had trouble with include JumpTap, AdMob, and, to a lesser extent, Millennial Media.
Related
I did find a lot of code to get current screen density in dpi and scale ratio and etc.
However what I am looking for a way to get a list of all densities that are shown inside the screen zoom view in device settings of a phone -
How do you get all available device densities via android studio?
please see a screenshot for more details on the question:
Thanks in advance!
You are mixing different things here. Density it's something tight to the device, in order to support dp and sp locally (based on screen resolution). Which means just factor to multiply pixels on this device.
You question "To get a list of all densities that are shown inside the screen zoom view in device settings of a phone" makes no sense. Since you are asking about some magic list of factors.
Now, to answer question, how to make something similar shown in the screen is pretty easy. You implementation starts with default and correct density supported by this device (as shown on image, we have centered slider), and just applying new factor changes of this density, based on user input from slider. So all your views should be aligned from encapsulated logic with using this changed scale factor (based on initial density of the device).
I've Unity Plus and I'm trying to find out the optimum android splash screen size that fits all android devices as there's no option to specify multiple images with different resolutions for android.
So far I've tried 768x1024, 1536x2048 on every option(center, fill, fit), however some nexus tablets/phones won't display the splash image full screen correctly.
Is there an optimum/suggested image resolution/configuration for android devices that most likely fit all?
There is a Splash Scaling property in Player Settings for Android builds. Try setting it to Scale to fill (cropped). Your splash image will be scaled without changing the aspect ratio.
We are using 1280x720 image in Unity 5.3.4 for android builds without any problem.
The image will be cropped but if there is not any sensitive text or symbol on the edges that will not be a problem.
Hope this helps.
Generally, you'll want to include multiple copies of the image at different resolutions and aspect ratios in your deployment. For example, small and large, both with different ARs. You would read the screensize of the device and select the appropriate size image for the device.
To give more detail here, I worked on a game that targeted devices from small screen sizes (Galaxy Ace), to large tablets (Galaxy Note 10.1). We used our own splash screen implementation rather than unity's, and we calculated the aspect ratio of the device. We then checked the screen resolution. After that, we had enough info to select the appropriate resolution image for the screen. It costs a bit more space, but it looks nice and crisp on almost every device.
I would like my app to display correctly on any Android device, regardless of screen size, screen density or ratio of screen height to width. I want to support Android devices as old as API 8. I can create separate layouts for portrait, landscape and perhaps xlarge screens, but beyond that I don’t want to create different layouts for different densities or screen sizes.
I have read the Android guide on supporting multiple screens. I try to follow those guidelines, for example, for widgets I set their height and width to wrap_content or fill_parent, and I avoid using specific pixel measurements. For images, I provide alternative bitmap resources for different densities, or sometimes I use a specific size with density-independent pixels (dip), so the system will size it correctly on screen with different densities.
Over the past 2 years I’ve probably read that guide dozens of times.
I understand that I could define specific resources (e.g. layouts) for specific screen sizes and densities, but there are dozens or hundreds of phones I’d like to support, so that seems futile. I see table 3 in that guide shows some common dimensions for screens, but I want to make sure my app runs on nearly every phone.
It seems to me that what I need is to know is the narrowest screen (in dip) and the shortest screen. That is, I want to know the ratio of height versus width.
For example, in portrait orientation, perhaps I have a list of buttons or other widgets. I would really like to know which phone is shortest: has the largest ratio of width to height, so I can see if my layout is cut off at the bottom. Perhaps I also have 3 tabs: I would like to know the narrowest screen so I can make sure the tabs are not cut off on the right.
If I knew the minimum and max of h/w ratio for all the current Android phones, for portrait I could test on merely two Android Virtual Devices (or even just a custom screen in Eclipse).
I have taken to examining Wikipedia’s list of Android devices, but someone must have a better way.
Unfortunatly I still haven't found that. I have this link: List of displays by pixel density but not all are Android devices. I know there are a couple of weird devices with square screen ratios (motorolas). But I would simply stick to Google's screen sizes list and you should be safe for 99.9% of you users.
Edit1: stats about screen sizes and densities
Edit2: From my experience, I usually make 5 quick checks:
App on a HDPI phone with 16:9 ratio
App on a MDPI phone with 4:3 ratio
App on a XHDPI phone
App on a LDPI phone
App on a large screen tablet (usually MDPI)
I feel with those 5 cases I cover all screen densities (to check for image sizes in particular), most common screen ratios (4:3 & 16:9, to check all layout elements are accessible), and two most common screen sizes (phone & tablet).
i am making a game on different platforms, and i need to maintain a fixed aspect ratio while rescaling the game based on different device screen sizes...
1) so theres many different screen sizes because there are many different android, ios and blackberry devices. is there a suggested aspect ratio for all of them, a universal aspect ratio?
2) Otherwise, do each of these device have a different screen resolution (ie 540X480, 1024X720 etc)? Does that mean i have to target only a fixed number of mobile devices (ie 5), and mathematically find an aspect ratio for the screen resolution of each mobile device?
3) is there a more optimal way to do the above?
much appreciated!
When dealing with game screen sizes, you usually want to have an fixed screen ratio (depending on the type of game), not to give some people an advantage and others a disadvantage (due to users playing your game on different devices).
I develop on a 320x470 ratio (since this is the most common screen ratio for Android mobile devices). I suggest you develop your game based on this ratio.
When actually rendering the framebuffer, you either stretch it to fill the screen or you use a technique called letterboxing. Both have their pros and cons.
I hope this gave you a greater insight and maybe an idea how you are going to tackle your problem.
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.