Making an ImageButton - without button border nor highlight - android

I have two png-images for the pressed and released state of a button. I'd like to build a button that accomplishes the following:
Has no background/border (only those two images visible)
Does not highlight with a blue rectangle when clicked (only by cycling through those images)
Does not get activated, when the user clicks on a transparent part of the image.
As you can see, the button is not rectangular, so the last point mentioned above might be tricky.
I already tried to use an ImageButton and managed to meet point 1, but I failed at point 2.
Is there another View I can use, that does the work for me? If not, could you hint me what techniques I should look into to solve this?

Just use ImageView
One image set as background, second as src.
And it resolve all your problems

[Edit]
for third part- follow this https://stackoverflow.com/a/8086317/3811198
in short
Use a TouchListener instead of ClickListener
Inside the listener, if the event is MotionEvent.ACTION_DOWN, get the touch coordinates
Check the image's pixel at the coordinates you obtained earlier; if the pixel is not transparent, consider the button was clicked, otherwise ignore the event.

If you use setBackground = "#0xxx"; on button in xml file the borders will desappear. Basically making it transparent using alpha
android:setBackground = "#0AAA"

Related

How to implement a round shape UI in Android

I am working on a android project where i have to implement UI like below.
where center image is an product image, surrounded with a three buttons. On click of that it is going to redirect to some other screen.
Is there any one who did this before? Your prompt reply will be really appreciated thanks.
You can simply use FrameLayout.
Image that this UI is composed of 4 same size components, which overlapped with the transparent part.
Then you should make some filtering operations in onTouchEvent to avoid the confused clicking event, because once you click the component, the other components will wait to respond.
There are two way to filter.
Linear Programming in the math way
Judged by the color of pixel
Obviously, the second is a better choice. So, you can use getPixel(x, y), which belongs to the Bitmap, to get the color value at the specified coordinate. If it is a transparent color, then return false to pass the touch event to the next layer View or return true to intercept it.
After that you will get the correct clicking event in your own OnClickListener.

How to highlight a clicked portion of an image and display a description panel

I am trying to learn special effects in android. I want to add an image in my android application. When the user touch on particular portion of image, that portion should be highlighted and a description panel regarding that portion will be displayed (as displayed in the example).
An example is posted here
Please suggest any method that can be used for implementing this effect.
This is not a simple problem.
The simplest solution I'd suggest in to implement an OnTouchListener to get X and Y position of touch. Using its MotionEvent getX() getY() values . Compare it to your portions position to know which one to highlight.
The effect of displaying highlights over portions can be achieve by placing invisible pictures on top of the main one (that represent only the highlighted portion in its highlight color on a transparent background, see what I mean?) And set them visible on user selection. The description panel can be included in this invisible image or be another invisible layout to set visible on selection (for example included in a PopupWindow or so...)

Android: How to avoid presses outside the circle of a round button using wrap content?

Can anyone tell me how to avoid presses outside the circle of a round button since "wrap_content" doesn't seem to work. I used an image file to create the button. I appreciate any help. Thanks.
Only for Your understanding.. (By default android View is in Rectangle shape so it apply same for Button)
Set Touch Listener to your button and in onTouch() map X-Y co-ordinates for Circle area.
If it lies in inside area do what you want else return false.
Use Inset look at this tutorial http://www.anotherandroidblog.com/2011/07/01/button-hit-area-for-custom-graphics/
Implement TouchDelegates look at this tutorial http://www.vogella.com/blog/2012/04/15/android-using-touchdelegates/

Button expose effect android

following link has some button at the top like :: "DISEASES" , "FOOD & NUTRITION" , "PHYSICAL ACTIVITY"
http://www.bam.gov/sub_yourbody/yourbody_smilestyle.html
when you focus it it will grow and remove from it it will small
so question is how can i do it?
What you have to do is set selector for your button as shown in my previous answer.
And depending on your requirement set drawable larger than the normal ones for that particular state , that will create the same effect
You have to understand that there's a huge difference between a mouse as a pointing device and your finger. A mouse can easily hover across these buttons to give you the effect, but it doesn't work as well with a finger, as you'd need to slide your finger across the buttons to get the effect - and who slides their finger across buttons instead of just pressing them?
Anyway, I suppose you could create an OnTouchListener for your Buttons, and perhaps throw in some animations to get the effects.
But - like I said - I don't see a reason to do this. It seems utterly unnecessary.

android custom button

I need to create some custom buttons as shown in the image below
what is the best approach to follow?
thanks
Abdul Khaliq
That's a hard one. I made a lot of custom views, and the first thing I would thinking of is, made one Button with that above image, and handle onTouch by yourself so you can distinguish which area the user hit. There you can also change the state of the button, like changing the image to a bevel one e.g. when the left button is hit.
Can you imagine this ansatz?
You can place two transparent "invisible" buttons over the top of a background in a LinearView. Like two ImageButtons with a transparent png inside.
It is also possible to make this background animated when buttons are clicked using android animation class.

Categories

Resources