Reprinted please indicate the source:Http://blog.csdn.net/android_ls/article/details/8711766
Disclaimer: All image resources used by the project are sourced from the official Android client of Renren. The purpose of this application is to learn and communicate. If infringement is involved, please inform us, I will replace the related images in time.
I. Build an application framework. The custom class inherits the application and is used to store global variables and public resources. The Code is as follows:
Package COM. copyeveryone. android; import Java. util. using list; import Java. util. list; import android. app. activity; import android. app. application;/*** function description: used to store global variables and public resources * @ author android_ls */public class copyeveryoneapplication extends application {private list <activity> activitys = new shortlist <activity> (); // application entry @ override public void oncreate () {} public void addactivity (activity) {activitys. add (activity) ;}@ override public void onterminate () {for (activity: activitys) {activity. finish ();} system. exit (0 );}}
2. The code for the base class of the interface (activity) in the application is as follows:
Package COM. copyeveryone. android; import android. app. activity; import android. OS. bundle; import android. widget. toast;/*** Function Description: application interface (activity) * @ author android_ls */public abstract class appbaseactivity extends activity {@ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); (copyeveryoneapplication) This. getapplication ()). addactivity (this); setcontentview (getlayoutid (); // initialize the component setupview (); // initialize the data initializeddata ();} /*** layout File ID * @ return */protected abstract int getlayoutid ();/*** initialize component */protected abstract void setupview (); /*** initialize data */protected abstract void initializeddata ();/*** display the prompt information in toast format * @ Param message */protected void show (string message) {toast. maketext (getapplicationcontext (), message, toast. length_long ). show ();}}
3. The code for implementing the welcome interface (logo) is as follows:
Package COM. copyeveryone. android. ui; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. OS. countdowntimer; import COM. copyeveryone. android. r;/*** Function Description: Welcome interface (logo) * @ author android_ls */public class welcomeactivity extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. welcome); New countdowntimer (1000,100 0) {@ override public void ontick (long millisuntilfinished) {// todo auto-generated method stub} @ override public void onfinish () {intent = new intent (welcomeactivity. this, guideactivity. class); startactivity (intent); welcomeactivity. this. finish ();}}. start ();}}
Layout file welcome. xml:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/v5_0_1_welcome" android:orientation="vertical" />
IV. Implementation of the guiding interface and the animation principle of the interface effect: the animation sequence in which each image is executed, such as fade-in, zoom-in, and fade-in, after the image and text are switched, the image and text are gradually displayed, zoomed in, and gradually hidden ..., when the last execution fades, switch to the first one to achieve the loop effect. The Code is as follows:
Package COM. copyeveryone. android. ui; import android. graphics. drawable. drawable; import android. OS. bundle; import android. view. view; import android. view. animation. animation; import android. view. animation. animation. animationlistener; import android. view. animation. animationutils; import android. widget. button; import android. widget. imageview; import android. widget. textview; import COM. copyeveryone. android. appbas Eactivity; import COM. copyeveryone. android. r;/*** Function Description: guiding interface * interface effect animation principle: the animation sequence in which each image is executed, such as fade-in, zoom-in, and fade-in, after the image and text * are switched, the image and text * are gradually displayed, enlarged, and gradually hidden ..., when the last execution fades, switch to the first one to achieve the loop effect. * @ Author android_ls */public class guideactivity extends appbaseactivity implements view. onclicklistener {/*** register button */private button btnregister;/*** check the people I know */private button btnlookatthepeopleiknow; /* ** login button */private button btnlogin;/* the image display imageview component */private imageview ivguidepicture; /*** text description component corresponding to the displayed image */private textview tvguidecontent;/*** a set of image resources to be displayed */private drawa Ble [] pictures;/*** specifies a set of animation effects to be executed for each image. */private animation [] animations; /*** the number of images currently executed (Resource Index) */private int position = 0; /*** text description of the image to be displayed (one-to-one correspondence between the image and the text) */private string [] texts = {"childhood friends, do not forget", "sentimental, please cherish "," struggle, share "," thank you all the way "," Brave youth flying "," Never go far "}; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); tvguidecontent. settext (texts [position]); ivguidepic Ture. setimagedrawable (pictures [position]); ivguidepicture. startanimation (animations [0]);} @ override protected int getlayoutid () {return r. layout. guide ;}@ override protected void setupview () {ivguidepicture = (imageview) findviewbyid (R. id. iv_guide_picture); tvguidecontent = (textview) findviewbyid (R. id. TV _guide_content); btnregister = (button) findviewbyid (R. id. btn_register); btnlookatthepeople Iknow = (button) findviewbyid (R. id. btn_look_at_the_people_ I _know); btnlogin = (button) findviewbyid (R. id. btn_login); btnregister. setonclicklistener (this); btnlookatthepeopleiknow. setonclicklistener (this); btnlogin. setonclicklistener (this) ;}@ override protected void initializeddata () {pictures = new drawable [] {getresources (). getdrawable (R. drawable. v5_0_policguide_pic1), getresources (). getdrawable (R. drawable. v5_0_policguide_pic2), getresources (). getdrawable (R. drawable. v5_0_policguide_pic3), getresources (). getdrawable (R. drawable. v5_3_0_guide_pic1), getresources (). getdrawable (R. drawable. v5_3_0_guide_pic2), getresources (). getdrawable (R. drawable. v5_3_0_guide_pic3)}; animations = new animation [] {animationutils. loadanimation (this, R. anim. v5_0_policguide_welcome_fade_in), animationutils. loadanimation (Th Is, R. anim. v5_0_1_guide_welcome_fade_in_scale), animationutils. loadanimation (this, R. anim. v5_0_policguide_welcome_fade_out)}; animations [0]. setduration (1500); animations [1]. setduration (3000); animations [2]. setduration (1500); animations [0]. setanimationlistener (New guideanimationlistener (0); animations [1]. setanimationlistener (New guideanimationlistener (1); animations [2]. setanimationlistener (New guid Eanimationlistener (2);} @ override public void onclick (view v) {Switch (v. GETID () {case R. id. btn_register: Show ("sorry, this function is not available now! "); Break; case R. Id. btn_look_at_the_people_ I _know: Show (" sorry, this function is not yet available! "); Break; case R. id. btn_login: break; default: break;} class guideanimationlistener implements animationlistener {private int index; Public guideanimationlistener (INT index) {This. index = index ;}@ override public void onanimationstart (animation) {// todo auto-generated method stub} @ override public void onanimationend (animation) {If (index <(animations. length-1) {ivguidepicture. startanimation (animations [index + 1]);} else {position ++; If (position> (pictures. length-1) {position = 0;} system. out. println ("position =" + position); tvguidecontent. settext (texts [position]); ivguidepicture. setimagedrawable (pictures [position]); ivguidepicture. startanimation (animations [0]); }}@ override public void onanimationrepeat (animation ){}}}
Layout file guide. xml:
<? XML version = "1.0" encoding = "UTF-8"?> <Framelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <relativelayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <imageview Android: Id = "@ + ID/iv_guide_picture" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: layout_weight = "1.0" Android: scaletype = "fitxy"/> <linearlayout Android: id = "@ + ID/ll_bottom_action_bar" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: Rule = "true" Android: Orientation = "horizontal" Android: padding = "7dip"> <button Android: Id = "@ + ID/btn_register" Android: layout_width = "fill_parent" Android: layout_height = "45dip" Android: layout_weight = "1.5" Android: Background = "@ drawable/guide_btn_blue_selector" Android: gravity = "center" Android: singleline = "true" Android: text = "" Android: textcolor = "# ffffff" Android: textsize = "15.0sp"/> <button Android: Id = "@ + ID/btn_look_at_the_lele_ I _know" Android: layout_width = "fill_parent" Android: layout_height = "45dip" Android: layout_marginleft = "8dip" Android: layout_marginright = "8dip" Android: layout_weight = "1.0" Android: Background = "@ drawable/guide_btn_white_selector" Android: gravity = "center" Android: singleline = "true" Android: text = "look at people I know" Android: textcolor = "#000000" Android: textsize = "15.0sp"/> <button Android: Id = "@ + ID/btn_login" Android: layout_width = "fill_parent" Android: layout_height = "45dip" Android: layout_weight = "1.5" Android: Background = "@ drawable/guide_btn_blue_selector" Android: gravity = "center" Android: singleline = "true" Android: text = "login" Android: textcolor = "# ffffff" Android: textsize = "15.0sp"/> </linearlayout> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_abve = "@ + ID/ll_bottom_action_bar" Android: layout_marginbottom = "40dip" Android: Orientation = "vertical"> <textview Android: Id = "@ + ID/TV _guide_content" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_gravity = "center_horizontal" Android: gravity = "center" Android: textcolor = "# ffffff" Android: textsize = "25366sp" Android: textstyle = "bold"/> </linearlayout> </relativelayout> </framelayout>
Resource file guide_btn_blue_selector.xml:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/v5_0_1_guide_blue_default" android:state_focused="true" android:state_pressed="false"/> <item android:drawable="@drawable/v5_0_1_guide_blue_press" android:state_pressed="true"/> <item android:drawable="@drawable/v5_0_1_guide_blue_default"/></selector>
Resource file guide_btn_white_selector.xml:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/v5_0_1_guide_black_default" android:state_focused="true" android:state_pressed="false"/> <item android:drawable="@drawable/v5_0_1_guide_black_press" android:state_pressed="true"/> <item android:drawable="@drawable/v5_0_1_guide_black_default"/></selector>
Progressively import the animation resource file v5_0_javasguide_welcome_fade_in.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:fromAlpha="0.0" android:toAlpha="1.0" /></set>
Enlarge the animation resource file v5_0_1_guide_welcome_fade_in_scale.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:fillAfter="false" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:toXScale="1.1" android:toYScale="1.1" /></set>
The gradient animation resource file v5_0_javasguide_welcome_fade_out.xml:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:fillAfter="false" android:fromXScale="1.1" android:fromYScale="1.1" android:interpolator="@android:anim/decelerate_interpolator" android:pivotX="50.0%" android:pivotY="50.0%" android:toXScale="1.1" android:toYScale="1.1" /> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="1.0" android:toAlpha="0.0" /></set>
Note: The pictures involved are available in the official Android app of Renren.
V. Run:
I wanted to record a video segment so that the animation effect would be clear at a glance. Unfortunately, I cannot find a solution. If any of your friends knows, please let me know. How can I upload a video to csdn?
The following content is to be continued...