put background with specific size and position - android

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.

Related

How to can I create an image that can be used for different android screen sizes?

I created an image to use for an android splash screen and it displays properly on my phone however when I open the app on a phone with a larger screen it pixelates. So I was wonder if I should create more than one image and if so what sizes should I set for other images because I know I can't use the same sizes as I used for the app icon?
If the images are pixelated
then you need to add larger images for each screen size under your
res folder. sizes depends on your target
or
scale the images. to be safe, make it bigger
it might help you: am I supposed to make images larger for tablets, or same size as handset?
you could probably use draw-9-patch to state which area of the picture can be extended.
Google draw-9-patch
I worked with two approaches so far:
Screen composition
One approach can be using a composition of brackground and a logo. You can have the logo as big as you need (for high resolution screens) and the background as a repeatable texture (it all depends on your design approach) or a gradient or other composition (less prone to pixelation errors).
As big as possible approach
If one image is your approach, you should do a research to know the currently most used and biggest android screen used (https://developer.android.com/about/dashboards/index.html). Knowing that one, you can design your image for that [high] resolution and set the scaleType as CENTER_CROP. With that, you will ensure that the image will be centered, inside the screen, keeping aspect ratio, and at its highest resolution [keep an eye about logos/graphics positions if you want to be sure that they remain visible even in thin screens).
For icons, the best way is Draw 9-patch
Otherwise, you need to scale the images into drawable-xx (res directory), here the explanation

How to make an Android UI with images from a designer delivered as layers

I hired a designer to help me redesign the UI for my Android app. For each Activity he gave me an image for the background, which includes any static content like fancy frames for text content; plus images for the buttons, which must fit in to the background image in exact places, to fit into the frames in the background image.
However, since Android devices have different screen sizes and aspect ratios, it's easy to fit the background image by itself with android:scaleType="centerInside", but how can I get all the other images to fit in with background exactly, to the pixel? If they didn't have to fit in with the background, I would just set the exact width and height for each ImageButton, but depending on how the background scales (based on the screen size and ratio) they might end up not aligned correctly.
Thank you very much in advance.
Update:
Is there some way I can have an entire view (e.g. a RelativeLayout) scale inside the screen, like the way the image scales inside the ImageView with scaleType="centerInside"? If so, I would be able to set the RelativeLayout's size to the same as the background image, and put all of the other buttons / images in their places relative to the background image, and then just have the whole thing (the RelativeLayout containing all the other views) center inside the phone's screen.
Your approach is wrong (or at least bad), because android devices offer screens not only with different sizes but also with different densities. What you shall read now is Designing for Multiple Screens first. Then understand that non scallable bitmaped UI will rather not work as you imagine. You need to support screen sizes which means your UI elements (like i.e. buttons, lists, headers etc) shall scale. There's lot of possibilities to deal with this, one is using 9-patch bitmaps (randomly chosen tutorial on the 9-patch).
Also, please read this article: Supporting Multiple Screens
When desining UI it suffices to assume you design for mdpi density. Once your layout is done you create drawables for i.e. mdpi and hdpi (and put under the same names into res/drawable-mdpi and res/drawable-hdpi respecitvely). Layout files remains unchaged but framework would automatically pick right asset so your UI will look sharp as long as you provided drawables for that density. Please see Providing Resources article as well.

Android background image for multiple screens

I read a topic about multiple screen support, but I don't understand why I need a different picture for every screen size if I can stretch image by setting
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bk"
for every screen.
You don't have to have a different image for each screen size. You certainly can just use fill_parent and just use the same image. The only issue is that it usually won't look as good. In fact, in some cases it will look absolutely terrible. Assuming that you're fine with your image being stretched though, you can just use one image.
If your background image is not a plain image, and has a lot of detail, then it renders better if it is the exact size needed. Shrinking a large image to small may make it look grainier than you want.
However, you can still do it. Make sure to make AVDs with different screen sizes, so you can see how it might look.

Fit Image on an android screen

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.

Android: Background image / imageView for different screens

I want to set a background image to my Activity. I am just using an imageView in a relative Layout and position the other elements as I want them. Now we have a million, or at least quite a few, different screen sizes and densities. I wonder how I can achieve having the right image for all these devices.
I don't want to scale/stretch my image.
The image is in a way that it is lets say 2000 x 2000 pixels (or whatever you like) it doesn't matter what part of this image is displayed. In other words I could crop any needed image size out of this extra large image and display only that portion.
How can I achieve this?
Thanks,
A.
Just set your image view android:scaleType="center" and it won't scale or stretch.
Have a look at the scaleType options at the following link. This gives you a decent amount of control over how an image is rendered.
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Also have a look at the following link. You can provide resources with the same file names in different folders, and the system will choose the most appropriate. This way, you can know more or less what size screen you are targeting with each image and you can create your images at a size that will perform the least cropping (or possibly no cropping at all).
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

Categories

Resources