Android implementation of the Flash screen and the countdown to the top right corner jump instance code _android

Source: Internet
Author: User

Before the time of programming, encountered the countdown function, often write their own, but in fact, Android has helped encapsulate a countdown class Countdowntimer, in fact, the background of the creation of the thread and handler queue encapsulation became a convenient class call.

The splash screen page uses the handler and Countdowntimer classes, and also needs to configure the subject of the activity, here is: Android:theme= "@android: Style/theme.notitlebar.fullscreen" The meaning of the full screen theme.

To show you the effect of the picture:

The code looks like this:

Package com.example.shanping;
Import java.lang.ref.WeakReference;
Import Com.example.shanping.MyActivity.MyCountDownTimer;
Import Android.os.Bundle;
Import Android.os.CountDownTimer;
Import Android.os.Handler;
Import Android.os.Message;
Import android.app.Activity;
Import android.content.Intent;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.widget.TextView; 
public class Mainactivity extends activity {private Mycountdowntimer MC;
Private TextView TV; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main); 
TV = (TextView) Findviewbyid (R.ID.TEXTVIEW1); 
MC = new Mycountdowntimer (3000, 1000);
Mc.start (); Handler.postdelayed (New Runnable () {@Override public void run () {Intent intent=new Intent (mainactivity.this,myactivity
. Class);
StartActivity (Intent);
}, 3000);
Private Handler handler=new Handler (); /** * Inheritance Countdowntimer Protection * * Override method of Parent class Ontick (), OnFinish ()/class MycouNtdowntimer extends Countdowntimer {/** * * * @param millisinfuture * Indicates total number of milliseconds countdown * * For example, the millisinfuture=1000 represents 1 seconds * * @param countdowninterval * Indicates how many microseconds to call once Ontick method * * For example: countdowninterval = 1000;  Represents a call to Ontick () */Public Mycountdowntimer (long millisinfuture, long Countdowninterval) {super (millisinfuture) every 1000 milliseconds. 
Countdowninterval); 
public void OnFinish () {Tv.settext ("jumping"); 
The public void Ontick (long millisuntilfinished) {tv.settext ("+ millisuntilfinished/1000 +")); } 
}
}

Here's a piece of code to share. About Android Implementation splash screen interface effect

Splash screen, is splashscreen, can also be said to start the screen, is the start of the time, Flash (show), lasted a few seconds, automatic shutdown.

The Android implementation is very simple and can be achieved using the Postdelayed method of the handler object. Pass a Runnable object and a delay time in this method. This method implements a deferred execution effect, which is specified by the 2nd parameter in milliseconds. The first parameter is the Runnable object, which contains the actions that need to be performed after the delay. The demo code is as follows:

Java code:

Package Com.mstar;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.os.Handler;
public class Actsplashscreen extends activity{
@Override
protected void onCreate (Bundle savedinstancestate) { C8/>super.oncreate (savedinstancestate);
Setcontentview (R.layout.shan);
The core code for the splash screen is
new Handler (). postdelayed (New Runnable () {
@Override public
void Run () {
Intent Intent = New Intent (Actsplashscreen.this,dialogtest.class); Jump from the start animation UI to the main UI
startactivity (intent);
ActSplashScreen.this.finish (); End start Animation interface
}
, 3000); Start animation lasts 3 seconds
}

XML code:

<?xml version= "1.0" encoding= "UTF-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:orientation=" vertical "
android:layout_width=" fill_parent "
android:layout_" height= "Fill_parent"
>
<textview
android:layout_width= "fill_parent"
android:layout_ height= "Fill_parent"
android:text= "Flash"
>
</TextView>
</LinearLayout>

Related Article

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.