Shaking Things Up

What if the user tries to enter an obviously invalid number, such as a number that already appears in the three-by-three block? Just for fun, let's make the screen wiggle back and forth when they do that. First we add a call to the invalid number case in setSelectedTile( ).

2. The two numbers on the bottom row's middle block are wrong.

Download Sudokuv2/src/org/example/sudoku/

Log.d(TAG, "'setSelectedTile: invalid: " + tile); startAnimation(AnimationUtils.loadAnimation(game, R.anim.shake));

This loads and runs a resource called R.anim.shake, defined in res/anim/ shake.xml, that shakes the screen for 1,000 milliseconds (1 second) by 10 pixels from side to side.

Download Sudokuv2/res/anim/shake.xml

<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android=""




android:interpolator="@anim/cycle_7" />

The number of times to run the animation and the velocity and acceleration of the animation are controlled by an animation interpolator defined in XML.

Download Sudokuv2/res/anim/cycle_7.xml

<?xml version="1.0" encoding="utf-8"?>

<cycleInterpolator xmlns:android="" android:cycles="7" />

This particular one will cause the animation to be repeated seven times.

0 0

Post a comment