Android alpha animation animating all ImageViews instead of just the calling ImageView
-
I'm implementing a board game for a course I'm taking. There are 5 "racks" (ImageViews), 1 for each of 5 players. The way I wish to show the current player is to have their rack "highlighted" (achieved through setting the alpha value). Now, this could be done successfully by just calling the setAlpha method, but it's a little jarring to go straight from one to the other, so i'd like to use an alpha animation. My issue is that, when the current player switches, I want to dim the highlighted rack, and highlight the next rack. It does this fine with those two racks, but in addition, every OTHER rack does a "dim", in that it immediately brightens and slowly dims back down. Makes the game look rather bizarre. So the two that I want to change are changing correctly, but all the others should just stay dim. I have the following code set up for it: dim.xml: <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.75" android:toAlpha="0.5" android:duration="1000"/> highlight.xml: <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.5" android:toAlpha="0.75" android:duration="1000"/> dim and highlight methods: dim = AnimationUtils.loadAnimation(gui, R.anim.dim); dim.setFillAfter(true); highlight = AnimationUtils.loadAnimation(gui, R.anim.highlight); highlight.setFillAfter(true); public Runnable dim(final Player player) { return new Runnable() { public void run () { dim.reset(); player.getRack().clearAnimation(); player.getRack().startAnimation(dim); //player.getRack().setAlpha(128); continuation(); } }; } public Runnable highlight(final Player player) { return new Runnable() { public void run () { highlight.reset(); player.getRack().clearAnimation(); player.getRack().startAnimation(highlight); //player.getRack().setAlpha(192); continuation(); } }; } The places it's called (denoted by asterisks): public void setup() { int starting = (int)(Math.random()*players.size()); curPlayer = players.get(starting); observer.execute( *** observer.dim(players.get(0)), *** observer.dim(players.get(1)), *** observer.dim(players.get(2)), *** observer.dim(players.get(3)), *** observer.dim(players.get(4)), *** observer.highlight(curPlayer) ); } public void draw() { if(deck.isEmpty()) { //Game over return; } Question q = deck.pop(); String answer = q.answer(curPlayer); answers.add(answer); Player oldPlayer = curPlayer; curPlayer = players.get((curPlayer.getPlayerNum() + 1)%players.size()); observer.execute( observer.ask(q.getQuestionText()), observer.say(answer), *** observer.dim(oldPlayer), *** observer.highlight(curPlayer) ); } Any ideas??? I'm hitting a wall with this and can't seem to find an answer anywhere. Sorry for the large amount of code!
-
Answer:
I'm not familiar with the observer classes you're using. Try 2 things: 1) Re-load your animations on each dim/highlight call. 2) Try without observer in draw (explicitly call startAnimation). I'm assuming the observer class is going what it appears to be doing, and #2 won't make a difference, but its something to try. If you're using observer to allow those operations to be called in the UI thread, create/use a Handler.
user1028885 at Stack Overflow Visit the source
Related Q & A:
- How to animate a View with Translate Animation in Android?Best solution by Stack Overflow
- How to animate the imageview outside of its parent layout?Best solution by Stack Overflow
- How to do android dialog flip animation?Best solution by developer.android.com
- How to add a colored border on the Imageview?Best solution by Stack Overflow
- Graduate Membership Alpha Kappa Alpha?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.