Android TransitionDrawable ImageView over-performance instance
Achieve the Transition effect Transition Drawable of the two images to achieve the dynamic excessive effect between the two images.
Run the following command: the first is the initial interface, the second is the excessive interface, and the third is the end of the transition.
Create a TransitionDrawable Android project.
Directory structure:
The main interface activity_main.xml code is as follows:
The main interface is a button that applies TransitionDrawable.
Transition is in the drawalbe folder, and its code is as follows:
The strings. xml Code is as follows:
TransitionDrawable
Hello world!
Settings
Transition Effect
The colors. xml Code is as follows:
#ff0000
#00ff00
The MainActivity. java code is as follows:
package com.shen.transitiondrawable;import android.app.Activity;import android.graphics.drawable.TransitionDrawable;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}public void change(View v){TransitionDrawable drawable = (TransitionDrawable)((Button)v).getBackground();drawable.startTransition(2000);}}