android - Animation prevents click event - android

I'm new on game dev for Android.
I have a game where I need to click on moving Buttons or TextViews(not important).
I extended FrameLayout class and added some Buttons(through addView method). Then I tried to use TranslateAnimation, but it seems it doesn't updates coordinates for click event (i.e. when I click on the moving button on new position, the event is not handling, but when I click on the origin place(where it has started moving), the event catches even if the button left this place).
Question: How to create a moveable label(or button) that handles click events? Do I need to use tricks like hit testing? Or, may be I use completely wrong approach for games(e.g. I need to draw text instead of adding the views in layout)? I will be happy if you can suggest another solution.

This is limitation of the Animation in Android. They fixed that in Android 3.0. Read here for more information http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html
An excerpt:
"Finally, the previous animations changed the visual appearance of the target objects... but they didn't actually change the objects themselves. You may have run into this problem. Let's say you want to move a Button from one side of the screen to the other. You can use a TranslateAnimation to do so, and the button will happily glide along to the other side of the screen. And when the animation is done, it will gladly snap back into its original location. So you find the setFillAfter(true) method on Animation and try it again. This time the button stays in place at the location to which it was animated. And you can verify that by clicking on it - Hey! How come the button isn't clicking? The problem is that the animation changes where the button is drawn, but not where the button physically exists within the container. If you want to click on the button, you'll have to click the location that it used to live in. Or, as a more effective solution (and one just a tad more useful to your users), you'll have to write your code to actually change the location of the button in the layout when the animation finishes."

Related

Android How to make only part of the screen clickable?

I am going to code a walkthrough tutorial for my app.
I wish the user will follow the step of the tutorial. So I want to force the user to click on a specific button but not other parts of the app.
My app has many UI components and some of them are added programmatically so disabling them one by one is not practical.
One immediate solution is that I make a transparent Activity to cover the original Activity.
But I don't know how should I detect the touch event through the overlay Activity to operate the original Activity.
Or are there any better way to make a walkthrough tutorial on android apps without much affects to the original code? Tutorial is an adhoc feature and I dont want these adhoc features to ruin my coding with a lot of if-statement on every Activity.
Thank you.
Activity won't work. Only the one at the top of the stack can process infos.
Simply add a semi-opaque view above the screen using a relativelayout
Then simply monitor the ontouch event of this view. If the touch is in the accepted zone of the tutorial, then let it bubble up to underneath control. If if is outside the accepted zone consume the event.
Button btn = new Button(getActivity());
btn.setText("Next");
// Adding button to bottom
lv.addFooterView(btn);

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 - Animation movement of container does not correctly update contained buttons hitboxes

So I have an application running on Android 2.2 (on a HTC desire). When the user presses the menu key, my menus silkily slide in from top and bottom. This works just great. Or so I thought. It turns out that even when the ImageButtons are off screen and invisible, the hitboxes of the places where they were before I moved them out of sight activate the buttons.
I have tried:
_top_slide_out_menu.forceLayout();
_top_slide_out_menu.recomputeViewAttributes(_measure);
_top_slide_out_menu.computeScroll();
No difference. At a guess it may be because I am moving the parent container object using the animation rather than the buttons themselves. I can only hypothesise that there is a bug that does not update the child hitboxes.
This bug seems to also affect subsequent animations I apply to the button. I have a animation I run on a button that I have previously moved using a different animation. This second animation shrinks then grows the button to give the impression of a click. Only half of the button is redrawn, as that is the half contained within the area of the origional button location.
So the question is, has anyone run into this? Is there anything to try other than moving all the buttons individually (which would get rather tiresome)?
I'd appreciate any ideas at this point!
Thanks
Android animations only shifts the pixels of the UI controls when you add animations to them. To actually update the layout after the animation, you should implement an animation listener and manually update the layout other wise the old layout will still remain with the only the pixels shifted.

How to get iphone like animation for button in android

I saw one iphone application if the button is visible and we press cancel button then that button should gone. in that case there is animation "the button diposes from left to right and finally got vanished". In android i am able to rotate any view or move it from left to right. But how can i get the effect that the button destroy animation and make a button visible in that type of animation.
Thanks
Deepak
I'm not sure that I fully understand what you're trying to do, but it seems like you want to fade the button as well as translating it. If that's the case, then you can use alpha animations to change the opacity of the button. By gradually reducing the alpha to 0, the button will appear to fade away.
I have recently completed a series on animations on my blog. It is probably best to read the articles in order starting with the first, but the final article covers animating individual widgets.
To get a general idea of animations in android, check out this awesome page on quick actions. There is plenty of code and working animations with different options so you can get a full tutorial of how they work.
How to create quick action dialog

Down state on clickable TextView

I have a clickable TextView with a drawable as its background. I'm looking for the right way to implement a down-state drawable so the background changes when the user presses down. I have been able to almost perfectly replicate this behavior by listening for MotionEvents and changing the background when the user is pressing down.. The only thing that doesn't match up with system-wide down state behavior here is that if the user keeps holding down and moves their finger off the button, the state remains down until they release their finger from the screen... whereas in Maps overlays or Buttons or ListViews or anything else the state immediately goes back to off when the finger moves from the object.
I know there must be some proper way to go about doing this... A nudge in the right direction would be great!
Thanks,
Nick
You need to use a Selector for the background. I'm not sure if there is an official example of how to use Selectors, but I found this site that seems to have a pretty good example:
http://www.craiget.com/2009/03/restyling-android-imagebuttons/
That should get you on the right track.
Edit: Apparently that first link is down, until/unless it comes back here is another example: http://www.mkyong.com/android/android-imagebutton-selector-example/

Categories

Resources