I'm having a trouble here on hot to make my background image fit on a high resolution screen. It works just fine in a 4" screen but image won't stretch out when I deployed it on a larger screen. I tried to search for an answer but nothing helps as of now. well this might be a problem with my xml code but I'm not really sure. My design works with 1 table layout and 2 table rows for the 2 objects. And on the LinearLayout I set my background image.
For further understanding I made a sample on how it looks like when deployed.
There you go. It works fine on my phone while It doesn't occupy the whole space in Galaxy tab. Also as much as possible I would like to make my background image in smaller size around 320x480 pixel is size and just stretch it out.
Set your layout height and width to FILL_PARENT?
Its clear that you did not set Layout_height and Layout_width to fill_parent .
also for better rending put images in all three drawable folders drawable-mdpi, drawable-ldpi,drawable-hdpi .
also make your background image as 9patch will be nice for resizing a backgrond .
Well there are so many reasons I could point out for this problem of yours.
1)First thing the first screen shows a mobile screen and the next one shows a tab avd.
2)The image what u have should be in size to fit a mobile of particular resolutions only.
So your only hope is to get a image with resolution that fits the tab.
Or to change the wrap content to fill parent for your width and height.
Related
I have a JPEG photo which I want to use to as a background for one of the screens.
I want the behaviour to be simlar to the css backgroundSize: cover property. (Play with the following tool to see what I mean: https://davidwalsh.name/demo/background-size.html)
For iPhone, this issue is fairly easy, as you can literally have several different versions of the same image depending which iPhone the app is being installed on.
For Android, this is much more difficult as they have various different aspect ratios and resolutions.
Therefore my question is, how can I specify an image that covers the entire screen.
You can always fake this by adding the imageview inside a View and calculate the proper height/width you need to cover the screen (get the shortest side and scale it up and multiply the other side by the original ratio).
You could also use https://github.com/AndreaVitale/imageview that supports a cover mode
For Android, My suggestion is to use 9-patch Image instead of normal image. It will stretch it self to entire Screen, if you placed image as background
of Window it self as well as worked for ImageView perfectly.
Thank you.
i'm working on an Android application and i'dd like to put a background image. my problem when i set the android:background is that the image is show on all the screen.
i'dd like to have my background on only 50 % height and wide.
thank you
This depends on screen size of devices. I recommend that You read about supporting multiple screen sizes:
http://developer.android.com/guide/practices/screens_support.html
You can also do this programmatically, but is a bad practise. To get the result You want, You have to set a layout.xml for every screen size. It is also recommended that You better put that image inside an imageView, because of a good scaling on different devices.
I aplogise for the sparseness of detail but this is something most likely to be immediately obvious to someone.
I've added an ImageButton to a page layout and this displays fine when it's loading from layout-land but in layout-port the same thing is stretched upwards. The size of the image is being hardcoded to a particular value so I don't see how it can possibly be stretched.
Yes, android GUI component adjust itself as per screen resolution.
In portrait mode the height of the screen is changes and that why your button image is look like stretched vertically.one solution for this is to use high-resolution images or changing the layout as per screen rotation.
Also have a look at android-supporting multiple screens
I am working on an app which should display several same size images on the screen. But it should only display only so much images as possible without offering scrolling.
E.g. On a "big" tablet it could display 10x10 Imageviews (screen is large, so there is much space for pictures)
On a "big" phone there might be enough space to display 6x6 ImageViews, so it should only display a 6x6 array of images.
On a small phone there is propably only space for 4x4 ImageViews, so it should only display this.
How can I make this in Android? I know about "layout-large", ... but if i make a special fixed xml-layout for a "large" device, it would not fit all devices correct. E.g. a Galaxy Nexus is a "normal" device and so is a Nexus One, but there would be at least be space for one or two more imageview rows on a Galaxy Nexus than on a Nexus One. So do I have to measure in code somehow how big the resolution is and display some TableRows accordingly? Or is there a special way how I can manage this?
you can query the properties of the screen of the device such as size, density etc. Once you know the size you can choose the layout to use.
Take a look at this stackoverflow post. Android: how to get screen dimensions
You should use a GridView to manage this.
GridView Android Developers
Edit: And indeed as Tomasz Gawel said: notice the GridView's android:numColumns="auto_fit" xml attribute
Edit: since you don't want it to be scrollable, you can just get the screensize, divide it by the size of your items, and put in only as much items as you want to display in the gridview.
The gridview will only scroll when it has more items than it can display.
getResources().getDisplayMetrics().widthPixels and heightPixels
I am using the Linear Layout Manager and I am trying to use the image width and height (wrapContent) automatically within the application. However, all of the images are appearing larger than what they should be. I think I know why: If I put an image that is 320X480 on the screen, on my device that has a pixel resolution of 480X800, it fills up the entire screen. This results in all of my images being too big for this screen, as I am building my images for a screen size that is 480X800.
Does anyone know how to fix this?
u can use absolute layout!
and can set the width and heigth of the image as u want!
go to the layout xml page and then change it to Absolute layout.
then you can easily change the the width ..
right click -> property
set the height and wigth as u like... Eg:"120dip"
it will solve your issue..
if not let me know will provide you another alternative