Android-enabled animation gradient and android-based animation gradient

Source: Internet
Author: User

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>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.