Photostream example: photos sized for larger screens - android

I'm using the Photostream example app to learn Android.
One thing I've noticed is that on my 800x480 4.0 phone the 6 photos in the grid fill the screen. However, on the 1024x768 pixel display of my 2.3 running touchpad they do not fill the screen, and are instead constrained to a tight grid towards the top-centre of the screen.
I want to adjust the app so it sizes itself appropriate to the screen size but I can't figure out why it's sizing the way it is.
Looking at the layouts in the res/ directory most of them specify fill_parent etc. The only explicit sizing I can see is the 150x128dip in grid_item_photo, but if I double this it seems to make no difference.
I tried changing the code in PhotostreamActivity.java to download SMALL instead of THUMBNAIL sized photos and it indeed seems to do that. However, it doesn't change the overall layout or sizing as they are cropped. This happens even with the above change.
I notice some sizing code in GridLayout.onMeasure() but this all seems to be driven by the existing size of the screen/widgets -- I don't see it enforcing an arbitrarily small size.
Another thing which occurred to me was that maybe it's to do with the resolution, but I don't see any hvga specific layouts or values in the res directory, just some overrides for landscape vs. portrait.
Why is the current code sizing things the way it does, and what is the best way to modify this so it works on physically larger, perhaps lower density screens?

I needed to add this to AndroidManifest.xml:
<supports-screens android:largeScreens="true" />
Apparently, it is not default on for all devices, unlike the other similar settings.

Related

Does `wrap_content` works the same way as Density Pixels?

I have read Android guidelines regarding different screen sizes, but still I have some considerations.
Client has given me an image from PSD file which has certain resolution that fits
1080 X 1920. I just use wrap_content, and it perfectly fits the part
of screen.
I am not using DP to define its width-height, If i was using DP it would have
adjusted image according to screen sizes.
My questions are,
Does wrap_content works the same way as Density Pixels?
Is it also responsive, and changes the image width-height according
to different screens?
If not, then Is it necessary to use DP to support different screen
sizes ?
Thanks
The setting wrap_content tells your view to size itself to the dimensions required by its content. In the case of your test, your image is 1080x1920 and your device's screen resolution is likely 1080x1920 as well, hence the perfect fit. Since you set the width and height to wrap_content, Android is simply trying to use as much screen space as it needs to correctly display the amount of content it was supplied. In this case, since the available screen space matches the size of the content, it just fits perfectly.
But what if the device screen isn't 1080x1920? In that case, Android will only use as much space as it can, but still attempt to fit the image inside the bounds of the available screen space. In other words, the system will appropriately scale the image down to get it in the container you have provided for it. But this can lead to awkward fits if the aspect ratio isn't the same as the image. For instance, see this screenshot below:
This image is 1920x1080, but notice that it doesn't quite fit. That's because this nexus 7 screen is 1824x1200 when viewed in landscape. Additionally, the toolbar at the top of the screen is eating up available screenspace, making my viewable area even smaller and more awkwardly shaped. So while the system would love this image to extend all the way to the left and right borders, it can't, because then that would mean the height would be bigger than the viewable space. Since I used wrap_content to display this image, the system is using as much vertical space as it can, and the result is that the image doesn't quite fit the horizontal space.
So to more directly address your questions, yes wrap_content is a relative size setting that will make it easier to get a consistent look across multiple screen sizes, similar to using dp. But realize that there are hundreds, if not thousands of available Android devices on the market, and they all have varying screen sizes and densities. So your drawables may not always appear the way you want them on every device.
The way to overcome this is to supply multiple versions of your assets and provide alternate layout files for different screen sizes and densities. Once you do that, all you can do is test, test, and test some more. Use emulators for weird screen densities or devices you don't own, just to make sure you're getting the look you want. In the case of your 1920x1080 image, it looks great on that one device, but how will it fit a large tablet or a tiny handset that is smaller than the resolution of the image? These are situations you must account for in your design.
I suggest you read these resources, as they are hugely helpful in learning how to deal with issues resulting from varying screen sizes and densities:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html

Widgets appear smaller in Eclipse than on the phone

I am currently putting together an application for my HTC Evo 3D phone which has a screen resolution of 960x540. I have set up a custom layout configuration for designing the interface at this resolution. When in this configuration the widgets (texts views, seek bars etc.) appear small and compact, sparse on the screen. Whereas when I launch the application on my phone the buttons are considerably larger and fill the screen more. Is there some setting in Eclipse that will allow me to view the layout in the editor exactly as it would appear on my phone, allowing for easier design of the interface.
Many thanks, Mat.
with relevant code would be easer to help, however, if you are using dp unit measure, sizes will change according to resolution:screensize, not just resolution. I think also a "wrap_content" given to a textview/button etc. would change in size, because font size would be in sp. So, look if there is any emulator configuration that fits real device resolution AND screen size.
Take a look here for more info about measure units.
EDIT
so are you seeing it in eclipse in the graphical layout of yourlayout.xml? on the top bar of that window there's a dropmenu for display configurations, change it to see the layout in different screens (I don't see any 960x540 btw). however, if you really want to develop for one single device is a matter, but if you're going to release the app for different devices, you need some strategy to make flexible layouts. this is very useful.

how can i get my android app to properly display on a touchpad?

i created a game and released it, but really only tested it on phones and the emulator. later on i downloaded it on a touchpad and it confined to a small box at the top. through some searching i found that adding this code to my manifest:
android:resizeable="true"
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="false" />
i got it to fill up the whole screen, but everything is now horrendously out of proportion. is there a better way of going about this? do i need a separate layout xml for phones and touchpads? do i need to rewrite my original xml from the ground up?
Read this article:
http://developer.android.com/guide/practices/screens_support.html
By following the practices described in this document, you can create
an application that displays properly and provides an optimized user
experience on all supported screen configurations, using a single .apk
file.
...
Your application achieves "density independence" when it preserves
the physical size (from the user's point of view) of user interface
elements when displayed on screens with different densities.
Maintaining density independence is important because, without it, a
UI element (such as a button) appears physically larger on a low density
screen and smaller on a high density screen. Such density-related size
changes can cause problems in your application layout and usability.
...
The Android system helps your application achieve density independence
in two ways:
The system scales dp units as appropriate for the current screen density
The system scales drawable resources to the appropriate size, based on
the current screen density, if necessary
I think it is better to design your layout for every screen size and resolutions. It is easy in android. Copy your layout from "layout" folder of resources and paste it in the "layout-land", "layout-xlarge", "layout-xlarge-land" and ... folders and change those settings you need in them.
you can check this link:

Android screen resoulution problem

I'm writing a game for Android and can now test it on a second device, the Nexus 1. The game uses fix pixel-values, just using bigger cutouts of the background for high-res devices. So I thought there would be no problems. Somehow, however, the nexus 1 is making a specific image bigger than it should be (261*66 instead of 174*44). The picture itself as a resource is 174*44, so it's being stretched. Why? What can I do against it?
Edit:
Spritesheet = BitmapFactory.decodeResource(res,
R.drawable.bird_spritesheet);
Is the used code.
Edit 2:
Is there no way to tell the software to just use the size the picture is? I don't want to bloat my software by adding multiple pictures (/drawable-hdpi/ answer).
The pictures are supposed to be smaller on bigger screens.
what drawables folder to you have the picture in? If you put a copy of it in drawables-hdpi I think it will show up real size. It is really better to set things up in such as way that the final size in pixels it ends up is unimportant. Using pixels values is going to ensure that your app looks wrong on at least some of the screen sizes out there.
Because Android runs on multiple screen sizes and you use device independent pixels (DIPs), images get scaled to ensure they look the same on all devices. To avoid this, you can provide alternative resources for high density screens (in your case) and for low density screens.
More info about screens here

Android large-sized emulator produces regular size application in center of screen

I always used the standard emulator when testing and thought it was about time to see what it looked like in a higher res/density setting. I ran my application using WVGA854 which has a density of 240 (rather than the 160 I usually used). The result is my application sitting as its old size in the center of the screen. I don't specifically hardcode the application size anywhere that would produce this (except for background images, but there are other things like x,y positions that are still limited by the old size). What gives? I move over the high res images into the correct folders but it still appears to be forcing my app to a smaller size? The background below is set to 854 width in the HDPI (and MDPI folder) but it is still cutting it off? Using a surfaceView to draw the bitmaps.
Add the <supports-screens> element to your manifest, saying that you support large screens.

Categories

Resources