How to place a rectangular image background to a button in Android? - android

I am working on an Android GUI, and I want to place some buttons with image backgrounds on a vertical linear layout. I designed button graphics and saved it in .png format. Then, I created a new Android Icon set which will be later related with a button or an imagebutton view.
I can only select "launcher icon" because notification, actionbar, menu type of icons are not suitable (they are not color at first).
When I select "Center" option, my button images do not fully cover the button area. So I cannot align button images appropriately. When I select "crop" option, my button image is cropped and is no longer a rounded rectangle as I desire.
What can I do? Thanks for your patience in reading, it may be longer than necessary.

Related

set up different clickable part image android

Im working with android about image and onclick listener. The purpose of my app is to monitor the area that user clicks on the screen. For example, I have a picture containing a rectangular and a circle. Assume that the color of the whole picture is brown(wood). So when I click on the rectangular, the color of rectangle will change to yellow. When I click on the one part of the picture, the color of that part will change its color, but other parts do not change. So, Im thinking about the solution for this app. Do I have to cut this picture separately and put them into the screen by using relative review? Or is there any other way to do this(Set up a coordination system)?
Yes you have to cut this picture separately and put them into the screen by using relative review. For example two ImageView with your backgound.
You can slse the image as recommeded by the other post, or overlay the image with a RelitiveLayout with specific sized buttons (background = #android/color/transparent)

How to 9-patch so icon always stick with centered text

Basically, I wanted to have a button where text and icon stay in the middle of the button at all times. The Button has match_parent width and center gravity. I tried to use drawableLeft but that put icon on the left most of the Button and not next to the text.
So I'm trying to create 9-patch image as shown in the image above. Basically, I want all the text to stay in blue box with the cyan rounded rectangle (icon) next to it. The stretchable area is in red. However I just can't make it as the content area always overlap the icon.
Is this possible with 9-patch? Or should I wrap Layout around the TextView and use that as a button instead?
By the way, the included image is just to show what I plan to do. The actual image will be in other colors and without all the red.
When you create a nine-patch image, you put some black lines on the right and bottom of the image. These lines define the region that will be use to place the content inside of your image.
Here is an example :
It will look like this :

Android market like button using layouts and xmls

Could someone point me to links and/or ideas on how to design a button similar to the android market "Install Button" using XML alone. i don't want to create something from gimp / photoshop and use it as android:src.
Please reference to the picture below from
http://howto.cnet.com/8301-11310_39-57329887-285/get-the-ice-cream-sandwich-keyboard-on-your-android-phone/
If you notice the installed button it has a white rectangle stroke, black rectangle border, filled with blue.
[Note: the above picture does not belong to me, and link has been pasted indicating the copyrighted owner. The picture has been quoted as reference solely for the purpose of demonstrating the "installed" button and nothing else]
You can do that with a linear layout with a white background, and a button with blue background inside. Give smaller values for button size, so it fits inside to leave some space so white borders are shown. User a selector for button, to change it's color in different states. More about selector here

How to have a gallery with a changeable icon overlayed upon each image in Android?

I've got an array of images, which I want to display in a gallery.
I want each image to have a small icon overlayed inside it, on the bottom right hand corner (e.g. a light bulb).
When the user clicks on the image or the icon, the icon will change from the 'lighbulb_off' image to the 'lightbulb_on' image, and the index of the clicked image will be added to a Vector of 'clicked images'.
Is there a way to have a custom layout for each item in a gallery? If so, each gallery item could be the original image, with the icon positioned within it using a RelativeLayout.
Is there a way to have a custom layout for each item in a Gallery?
Yes. You need to extend ArrayAdapter and override getView() to do what you want. Here is a free excerpt from one of my books that discusses the concept -- while it uses ListView as the example, the same technique should apply for Gallery.
Note that this excerpt should be updated in the next ~12 hours to be much improved, so, um, don't rush to download it right away. :-)

Custom Map markers and custom backgrounds

I am trying to get the images to have transparent backgrounds so the map is not blocked by a square marker with an image in it. What image editor and what settings should I use to get this to work?
I am trying to do some custom backgrounds for buttons and the same problem comes up: I get square corners and a background that does not scale with the buttons.
I think this all part of the same problem: I am not using the right tool with the right settings to create the images. I must be misinterpreting the documentation and examples that talk about a white border around the image and a black line along the top and left side for the expandable button background.
Here's a quick way to reproduce the problem:
Follow the directions to create the MapView program as described on:
http://developer.android.com/resources/tutorials/views/hello-mapview.html
For the icon I first used the image copied from the page:
Next I edited the picture in Microsoft Paint, and cut off the little guy's antennae. I'm not cruel and no real androids were harmed in that experiment. I surrounded the new picture with a pixel thick border of white, copied from the border that was around the rest of the image, and then copied the black that was there as well in the void areas of the image, outside the border.
I saved the image as myandroid.png and copied the file to the layout folder. Pointed the activity to the new pic and ran the program.
The image was displayed with a full square background and shadow, not the android shaped image and shadow that was there when the original image was used.
Custom Button background:
Follow the directions for the Relative Layout example at:
"http://developer.android.com/resources/tutorials/views/hello-relativelayout.html"
Next, I created an image to expand as a background for the button called backbutton.png. It too is surrounded by a white border and black filled on the corners, the top and one side per documentation I found in "Android Programming Tutorials" on page 298.
The background does not expand, nor do the corners round.
I wish I could show you screenies of what I have.
How do you create the images for the custom backgrounds and the images for the custom map markers and buttons? I need to know what image editor to use and the file attributes to set, so the images expand and display with the proper void spaces in them.
Thank you in advance.
You used MSPaint to save the image did you define the transparent color?
should in Image > Attributes
To create custom backgrounds for buttons and other widgets that can change their size at runtime, you should create NinePatch images. The tool you should use is draw9patch and is available with the Android SDK.

Categories

Resources