Different states of one image - android

I am making an app for Andorid. There are 2 restrictions:
It must be light (2-3MB)
I need to have minimal graphic files (not having a file in diffrent state and option)
How to make the layout so I can modify only the red dots (image or code) for each option that is selected?
Making 6 different states of this image is not a good answer (too big data)

Make this image as two layered. One for your main button, and other for red dots(They should be PNG's and 6 of them for different dots).And place these PNG above your main button according to the choice(Make them visible/invisible). Do you have its PSD file btw?

Related

Android Images scaling

I always have problems when using images. I want to use an image as splash screen. So I imported all resolutions (ldpi to xxhdpi) of my image using Multisource-Drawable in Android Studio. Then, I created a imageview in my Activity and set Width and Height to 150dp both. It seems to use the ldpi resource and the image get very blurry.
What's the best way to import images in Android Studio to general use?
[UPDATE]
Android is chosing the right size, but not how I want. I fixed it by adding a 512x512 png file and then setting its Width And Height to 150dp
I think your question may have two separate answers. First, you are assuming that an image is the best way to set up a splash screen. This is not so, as the content would have to be called after the app has already finished setting up. That would mean your user sees a flash (or more) of a blank screen before the splash screen is shown. Second, you would like to know the best way to import images into Android Studio. Here are the two different answers:
#1 The best way to implement a splash screen is to have a theme called on a blank activity. The theme would include your desired image and background color. The reason for this is to eliminate the short break before content is called. Click here for a link describing more and giving a tutorial.
#2 In my opinion, the simplest and most robust way to add an image resource is to use the Image Asset import feature. Follow these steps:
Right click on "res" (in the Project View) -> New -> Image Asset
On Icon Type choose Action Bar
and Tab Icons
For Asset Type choose Image
Choose the image path (on your computer)
Give your image a name (no UPPERCASE, only lowercase and underscores, etc)
Next -> Finish
make image view height and width wrap_content and set its gravity to center..

What's the proper way to scale/size background images for Android?

I want to have an image cover the background of my Android game, but I'm new to Android development - are there conventions for what file type such an image should be?
What is a conventional size?
What's the proper way to scale/refit this image to different devices (right now I just added the imageresource to the back layout, but this scales the image and distorts it)?
I'm planning on using photoshop and drawing out the image there, is there a more recommended method?
Thanks
"Are there conventions for what file type such an image should be?" The image can be any common file format. PNG is common, probably because it's loss-less and supports transparency, but I don't know the details.
"What is a conventional size?" You will have to produce an image of various resolutions to support all the screens on which your game may be used. You can create new directories in your project tree that look like res/drawable-{screen-type}, where {screen-type} is a screen size/resolution/minimum dimension. For details on how this works see Supporting Multiple Screens.
"What's the proper way to scale/refit this image to different devices?" See #2. To avoid distorting your image, you will need to produce different sized/resolution images to fit various screen sizes.
With regards to Photoshop -- if you are producing a background with a complex design/graphic, you will probably want to use the graphics editor you know best, such as Photoshop. However, if you are making a background that will just be a simple pattern that repeats, or even just a solid, consider making just a small bit of the image, and then using an Android Shape Drawable or Nine Patch Drawable to tile/repeat/stretch your image. This will reduce the number of different-sized images you need to produce for different screens, and will also reduce the space your app takes up, since you will have fewer resources to package. For info on the Drawable resources that Android supports, see Drawable Resources.
The background drawable is stretched by default. If you want to change that, you can create an XML <bitmap> drawable resource referencing your image and set its gravity attribute to something different than fill.
The result can be better if your image is decomposed in different smaller images aligned properly. For exemple, a main background color, a top part and a bottom part. You can then combine the different layers with a Layer list drawable or using a custom layout.

nine patch image shows dots

I've created several 9-patch images using the android draw9patch utility and I've yet to make one that works. On one image I've got 2 dots on the top edge, and 2 dots on the left edge; the 'show bad patches' button shows no bad patches, and the samples on the right side look fine. However, in the app the image appears with the black 9patch dots showing on the top and right sides.
Are we suppose to set the backgroundColor or cachecolor to hide the dots in the imageview?
I'm targeting google maps 2.3.3. Could there be known issues with this API?
What is the full name that you gave to the file? The file name must end in ".9.png" to work properly. Otherwise it will be treated as a normal png file which would display the dots and lines at the edges of the image.
Those dots will go away when they're displayed on the phone. They tell the Android System what parts of the image can be stretched without warping how it's supposed to look. If you notice the format of the 9patch is .9.png, there's preprocessing that Android does before the image is displayed and the dots are removed. 'Show Bad Patches' rarely makes a difference I've found, even if they're considered 'bad' they work how I want them too. At least in my experiences. Just add the 9patches to your activity and reference them as you normally would
Update
Wait a second. Are you trying to use 9patches as images to be displayed in an ImageView? That's not what 9patches are for. 9patches are stretchable images for buttons or other UI elements (i.e. for different screen sizes) so developers can have one image to stretch and fit the different sized buttons instead of one for each size. Android displays most image formats in ImageView. If you're displaying the 9patches with an ImageView, Android isn't preprocessing the black dots as slices of that image that are repeatable, it's just displaying the whole thing.

Android Creating Custom Buttons

I have quite a few buttons in my application, they vary in sizes based on the text inside. I want to customize the buttons but I am not sure if I should use
A) Ninepatch pngs
B) Android xml created
C) Photoshop pngs
I want the buttons to scale nicely and therefore not look distorted based on screen size. What are the positives and negatives of the above methods? Is there an ideal way to go about this?
It depends on what they should look like. Rounded corners? Complicated images? Drop shadows? Plain colors?
If you want simple buttons that are monotone in color, xml drawables are the best solution. You can do rounded corners through xml, so if plain is what you are looking for this is the best option.
If you are working with an image, then a 9 patch is the way to go. Play around with the draw9patch tool that comes with the sdk to get the hang of it. You also don't necessarily only need to leave the corners in tack, sometimes you may want to break up the resizable area depending on the image.
PNGs are the last resort as they are the least flexible of the 3 options.
By the way, you should also consider using a state list for all of your buttons, regardless of how you implement the drawable that the button uses. See the link below:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Screen Size Resolution problem

I have Some Background image in to My Application. That background Image also contain the Button image. I am manualy create and set the Button on that Button image of the Background Image. now while the Screeen size changes for another device then the real button and the Button Image that show on the Background image shows different. How i can set it for the ProperView. Or if i want to make another Background Image that dont contain the Image of the Button. Then which Screen size should i have to prefer for different Device Competibility.
I have read this competibility documents. But not getting proper idea if i have to set the background image for all device then which screen size i have to prefer. So can any budy explain me in Short and Sweet ?
Thanks.
According to Supporting Multiple Screens, you have to create multiple layout folders!
For example: you can have 2 versions of my_layout.xml
res/layout-xlarge/my_layout.xml
res/layout-normal/my_layout.xml
Read Supporting Multiple Screens; There are lots of details there.
Read Supporting Multiple Screens; There are lots of details there.

Categories

Resources