public void onCLick(View view) {<br> LevelListDrawable levelListDrawable = (LevelListDrawable) imageView.getDrawable();<br> int level = levelListDrawable.getLevel(); level = level + 1;<br> level = level % 3;<br> imageView.setImageLevel(level);<br> }
ImageView iv = (ImageView)findViewById(R.id.imageview); LevelListDrawable lld = (LevelListDrawable)iv.getDrawable(); int temp = lld.getLevel(); lld.setLevel(3); Drawable d = lld.getCurrent(); lld.setLevel(temp);
/** * Launch the animation on the ImageView1 * And update the level of the drawable */ private void launchAnimVectorList() { if(!animatedVectorFirstLaunched) { if (animatedVectorList.getLevel() < animatedVectorListMaxLevel) { //then increment animatedVectorList.setLevel(animatedVectorList.getLevel() + 1); currentAnimatedVectorFromList = (AnimatedVectorDrawable) animatedVectorList.getCurrent(); } else { //go back to the beginning animatedVectorList.setLevel(0); currentAnimatedVectorFromList = (AnimatedVectorDrawable) animatedVectorList.getCurrent(); } }else { animatedVectorFirstLaunched=false; } //start the animation on the current element currentAnimatedVectorFromList.start(); //launch it again in 300 ms + the time your animation take uiHandler.postDelayed(uiRunnable,300+3000);//TODO instead of 3000 set your animation duration !!! }
/** * Launch the animation on the currentAnimatedVectorDrawable */ private void launchAnimBackup(){ if(!backupRoundTripFirstLaunched) { if (backupRoundTrip.getLevel() == 1) { //then reverse backupRoundTrip.setLevel(0); } else { //then reverse backupRoundTrip.setLevel(1); } }else{ backupRoundTripFirstLaunched=false; } //find the current AnimatedVectorDrawable displayed currentBackupDrawable = (AnimatedVectorDrawable) backupRoundTrip.getCurrent(); //start the animation currentBackupDrawable.start(); }