Android-enabled animation gradient and android-based animation gradient
1. Start the gradient of the animation:
Effects of starting an animation that may be used in the future:
:
Main Interface:
Public class MainActivity extends Activity {private LandingView lv; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_main); lv = new LandingView (this); // display the custom view on this interface setContentView (lv ); // create an asynchronous job LoGoTask task that modifies the Logo transparency = new LoGoTask (this, lv); // execute an abnormal job task.exe cute ();}}
Asynchronous image gradient:
Public class LoGoTask extends AsyncTask <Object, Integer, String >{// the current transparency value int alpha = 0; MainActivity main; private LandingView lv; public LoGoTask (MainActivity main, LandingView lv) {this. main = main; this. lv = lv ;}@ Overrideprotected void onPreExecute () {// TODO Auto-generated method stubsuper. onPreExecute ();}/*** after the asynchronous task is successfully executed, it automatically jumps to the main interface of the application **/@ Overrideprotected void onPostExecute (String result) {Intent intent = new Intent (main, TestActivity. class); main. startActivity (intent); main. finish ();}/*** modify the image transparency of the custom Logo view and redraw the image **/@ Overrideprotected void onProgressUpdate (Integer... values) {int temp = values [0]. intValue (); lv. redraw (temp);}/*** asynchronous task, cyclically changing the transparency value **/@ Overrideprotected String doInBackground (Object... arg0) {// TODO Auto-generated method stubwhile (alpha <255) {try {Thread. sleep (100); publishProgress (new Integer (alpha); alpha + = 5;} catch (InterruptedException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} return null ;}}
Display image creation:
Public class LandingView extends View {private int alpha = 0; private Bitmap logo; private Context context; public LandingView (Context context) {super (context); this. context = context; logo = BitmapFactory. decodeResource (context. getResources (), R. drawable. background1);} public void redraw (int aplha) {this. alpha = aplha; invalidate () ;}@ Overrideprotected void onDraw (Canvas canvas) {// TODO Auto-generated method stubsuper. onDraw (canvas); // clear screen canvas. drawColor (Color. WHITE); // create Paint p = new Paint (); // set the Paint object transparency to the current transparency value p. setAlpha (alpha); WindowManager manager = (WindowManager) context. getSystemService (Context. WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics (); manager. getdefadisplay display (). getMetrics (dm); int width1 = dm. widthPixels; int height2 = dm. heightPixels; // use a paint brush to draw the Logo image RectF rect = new RectF (, wid2, height2); canvas. drawBitmap (logo, null, rect, p );}}
Next, go to the interface:
public class TestActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }}
All use a uniform layout:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" ></LinearLayout>