Hello! There is a flipCard method that, when accessed, the button rotates around the y-axis in one direction or the other with the speed specified in setDuration () ( Animation looks like this ). I looped this process using TimerTask.
It is required to make so that with each turn of the button the text of the button changes to random, i.e. on each side at each turn there should be a new text, and the process of changing the text should be invisible to the user. I used the Random class and the setText () method, inserted this into the applyTransformation before and after fromView.setVisibility (View.GONE), but the text changes very quickly several times in a row on each side. In other places (runOnUiThread, flipCard and FlipAnimation) I also tried to insert, there the text changes once on each side, but this happens before the button is rotated, so the process of changing the text is noticeable.
Tell me, how can I solve this problem?
//...создание потока через TimerTask... runOnUiThread(new Runnable() { @Override public void run() { flipCard(rootLayout, cardFace, cardBack); } }); private void flipCard (View rootLayout, Button cardFace, Button cardBack) { FlipAnimation flipAnimation1 = new FlipAnimation(cardFace, cardBack); if (cardFace.getVisibility() == View.GONE) { flipAnimation1.reverse(); } rootLayout.startAnimation(flipAnimation1); } public class FlipAnimation extends Animation { private Camera camera; private Button fromView; private Button toView; private float centerX; private float centerY; private boolean forward = true; /* Тут создается анимация между 2 View. * * fromView - одна сторона кнопки. * toView - другая сторона кнопки. */ public FlipAnimation(Button fromView, Button toView) { this.fromView = fromView; this.toView = toView; setDuration(1000); setFillAfter(false); setInterpolator(new AccelerateDecelerateInterpolator()); } public void reverse() { forward = false; Button switchView = toView; toView = fromView; fromView = switchView; } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); centerX = width / 2; centerY = height / 2; camera = new Camera(); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { // Расчет угла поворота: final double radians = Math.PI * interpolatedTime; float degrees = (float) (180.0 * radians / Math.PI); /* При повороте кнопки ребром к наблюдателю один View исчезает, * а другой появляется; вместе с этим меняются градусы. */ if (interpolatedTime >= 0.5f) { degrees -= 180.f; fromView.setVisibility(View.GONE); toView.setVisibility(View.VISIBLE); } if (forward) degrees = -degrees; //определение направления движения при начале поворота final Matrix matrix = t.getMatrix(); camera.save(); camera.rotateY(degrees); camera.getMatrix(matrix); camera.restore(); matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY); } }
TimerTaskto call thesetText()method, setting the delay and the same repetition period as I used inTimerTaskto call animation. - Doraemon