Welcome interface + Guide into the classic case

Source: Internet
Author: User
Tags set background

Look at the Guide interface effect


First look at the layout of the Welcome Interface (animation effect)


Activity_welcome.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent "    android:id=" @+id/rl_root "    android:background=" @ Drawable/splash_bg_newyear ">    <imageview        android:layout_width=" match_parent "        android:layout_ height= "Match_parent"        android:src= "@drawable/splash_horse_newyear"/></relativelayout>


And look at the activity on the Welcome screen.

Welcomeactivity.java

Package Com.example.bjnews.activity;import Com.example.bjnews.r;import Com.example.bjnews.util.sputil;import Android.os.bundle;import Android.util.log;import Android.view.animation.alphaanimation;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationset;import Android.view.animation.rotateanimation;import Android.view.animation.scaleanimation;import Android.widget.relativelayout;import Android.widget.Toast;import Android.app.activity;import Android.content.intent;public class Welcomeactivity extends Activity {private Relativelayout rl_root; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_welcome); init ();} private void Init () {rl_root = (relativelayout) Findviewbyid (r.id.rl_root);//rotation rotateanimation rotateanimation = new Rotateanimation (0, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); rotateanimation.Setduration (+); Rotateanimation.setfillafter (true);//zoom scaleanimation scaleanimation = new Scaleanimation (0, 1, 0, 1, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Scaleanimation.setduration (2000); Scaleanimation.setfillafter (TRUE);//Transparency alphaanimation alphaanimation = new Alphaanimation (0.0f, 1.0f); Alphaanimation.setduration (+); Alphaanimation.setfillafter (true);//Add animation animationset Animationset = new Animationset (false); animationset.addanimation (rotateanimation); animationset.addanimation (scaleAnimation); Animationset.addanimation (alphaanimation); rl_root.startanimation (animationset);// Animation Listener Event Animationset.setanimationlistener (new Myanimation ());} Class Myanimation implements animationlistener{@Overridepublic void Onanimationend (Animation Animation) {// Whether you have entered the main interface (the default has not been entered) Boolean Isentermain = Sputil.getinstance (welcomeactivity.this). Getboolean ("Isentermain", false) ; LOG.E ("TAG", "Isentermain" +isentermain), if (Isentermain) {//entered, into the main interface startactivity (new Intent (WELCOMEACTivity.this,mainactivity.class)); LOG.E ("TAG", "Main");} else {//did not enter, counted into the wizard interface log.e ("TAG", "Guide"); StartActivity (new Intent (Welcomeactivity.this,guideactivity.class));} Finish ();} @Overridepublic void Onanimationrepeat (Animation Animation) {} @Overridepublic void Onanimationstart (Animation Animation) {}}}
also provides a tool class for the upper object (to save whether it is the first time to enter the app)

Sputil.java

Package Com.example.bjnews.util;import Android.content.context;import Android.content.sharedpreferences;import Android.content.sharedpreferences.editor;public class Sputil {//Constructors Private private Sputil () {}//Private, static instance private static Sputil instance = new Sputil ();//Public, static method gets the instance publicly static Sputil getinstance (context context) {if (sp = = null) {SP = cont Ext.getsharedpreferences ("Atguigu", Context.mode_private);} return instance;} private static Sharedpreferences sp;//method of saving data public void put (String key, Object defvalue) {Editor edit = Sp.edit (); if (DE Fvalue instanceof Boolean) {Edit.putboolean (key, (Boolean) defvalue);} if (defvalue instanceof String) {edit.putstring (key, (String) defvalue);} if (defvalue instanceof Integer) {Edit.putint (key, (Integer) defvalue);} Edit.commit ();} Get Data public string getString (string key, String defvalue) {return sp.getstring (key, defvalue);} public int getInt (String key, int defvalue) {return Sp.getint (key, defvalue);} public boolean Getboolean (String key, Boolean DEFVAlue) {return Sp.getboolean (key, defvalue);}} 

The next step is to start the boot interface.

First look at the layout

Activity_guide.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent         "android:layout_height=" match_parent "> <android.support.v4.view.viewpager android:id=" @+id/viewpager " Android:layout_width= "Fill_parent" android:layout_height= "fill_parent" > </android.support.v4.view . viewpager> <button android:id= "@+id/btn_entermain" android:layout_width= "Wrap_content" Andro id:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" Android:layout_centerhorizontal= "Tru E "android:layout_marginbottom=" 100DP "android:background=" @drawable/enter_main_button_selector_bg "a ndroid:text= "Start experiencing" android:textcolor= "@drawable/enter_main_button_text_selector" android:visibility= "Gone"/ > <relativelayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" a Ndroid:layout_alignparentbottoM= "true" android:layout_centerhorizontal= "true" android:layout_marginbottom= "80DP" > <linearlay Out android:id= "@+id/ll_point_group" android:layout_width= "Wrap_content" Android:layout_h            eight= "wrap_content" android:orientation= "horizontal" > </LinearLayout> <view            Android:id= "@+id/red_point" android:layout_width= "10DP" android:layout_height= "10DP" android:background= "@drawable/point_red"/> </RelativeLayout></RelativeLayout>
4 XML files are also required for the boot interface (click-to-effect toggle to experience button, and 3 state toggle dots)
Enter_main_button_selector_bg.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_checked=" true "android:drawable=" @drawable/button_red_pressed "></ item>    <item android:state_checked= "false" android:drawable= "@drawable/button_red_normal" ></item ></selector>

Enter_main_button_text_selector.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item android:state_checked=" true "android:color=" @android: Color/black "></item>    <item android:state_checked= "false" Android:color= "@android: Color/white" ></item></selector >

Point_normal.xml

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Oval" >    <solid android:color= "#55000000"/></shape>
Point_red.xml

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android:shape= "Oval" >    <solid android:color= "#ff0000"/></shape>

The next step is to pay attention to the wizard interface code.

Guideactivity.java

Package Com.example.bjnews.activity;import Java.util.arraylist;import Android.app.activity;import Android.content.intent;import Android.os.bundle;import Android.support.v4.view.pageradapter;import Android.support.v4.view.viewpager;import Android.support.v4.view.viewpager.onpagechangelistener;import Android.view.view;import Android.view.viewgroup;import Android.view.ViewTreeObserver.OnGlobalLayoutListener; Import Android.widget.button;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.linearlayout.layoutparams;import Android.widget.relativelayout;import Com.example.bjnews.R;import Com.example.bjnews.util.sputil;public class Guideactivity extends Activity {private Viewpager viewpager;// Three sliding pages private arraylist<imageview> imageviews;//three sliding pages corresponding Picture collection private button btn_entermain;//Start experience button private LinearLayout ll_point_group;//three display dots under private View red_point;//the highlight dot of the current page private int leftmax;// Distance before 2 origin @overrideprotected void OnCreate (Bundle saveDinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_guide);//Get a collection of points Ll_point_ Group = (linearlayout) Findviewbyid (r.id.ll_point_group);//Get the highlighted red dot red_point = Findviewbyid (r.id.red_point);// Get Viewpagerviewpager = (Viewpager) Findviewbyid (R.id.viewpager);//Get Button (start experience) Btn_entermain = (Button) Findviewbyid (R.id.btn_entermain);//Create collection imageviews = new arraylist<imageview> ();//Prepare data int[] ids = {  R.drawable.guide_1, r.drawable.guide_2,r.drawable.guide_3};for (int i = 0; i < ids.length; i++) {ImageView ImageView = New ImageView (this);//Create Picture Object Imageview.setbackgroundresource (Ids[i]);//Set Background Imageviews.add (ImageView) for picture;// Add Picture view point = new View (this);//Add Next punctuation-Create click layoutparams params = new Layoutparams (10, 10);//Create layout parameter//except NO. 0 point, the others are 1 from the left. 0 pixels if (i! = 0) {params.leftmargin = 10;} Point.setbackgroundresource (r.drawable.point_normal);//Add background picture point.setlayoutparams (params);//Set Layout parameters Ll_point_ Group.addview (point);//Add indication click}//Set Adapter Viewpager.setadapter (NEW Viewpageradapter ());//monitor when the OnLayout method executes, go to Red_point.getviewtreeobserver (). Addongloballayoutlistener (New Ongloballayoutlistener () {@Overridepublic void Ongloballayout () {//Unregister listener-because the child will also call Red_point.getviewtreeobserver () . Removeglobalonlayoutlistener (this);//spacing between two points Leftmax = Ll_point_group.getchildat (1). GetLeft ()-Ll_point_ Group.getchildat (0). GetLeft ();}); * * Set Page change listener */viewpager.setonpagechangelistener (new Onpagechangelistener () {@Overridepublic void onpageselected (int Position) {//Only the third page shows the Enter button if (position = = 2) {btn_entermain.setvisibility (view.visible);} else {Btn_ Entermain.setvisibility (View.gone);}} /* * Position screen sliding percent slide display */@Overridepublic void onpagescrolled (int position, float positionoffset,int positionoffsetpixels ) {//Calculate the distance to Slide = pitch * The percentage that slides on the screen int distance = (int) (Leftmax * (positionoffset + position)); Relativelayout.layoutparams params = new Relativelayout.layoutparams (ten);p arams.leftmargin = Distance;red_ Point.setlayoutparams (params);} @Overridepublic void Onpagescrollstatechanged (int arg0) {}})/** * Add Click event */btn_entermain.setonclicklistener for Start Experience button (new View.onclicklistener () {@ overridepublic void OnClick (View v) {//Marked as Truesputil.getinstance (Guideactivity.this). put ("Isentermain", true);// Enter the main interface startactivity (new Intent (Guideactivity.this, Mainactivity.class));//Kill yourself Finish ();});} Class Viewpageradapter extends Pageradapter {@Overridepublic int getcount () {return imageviews.size ();} @Overridepublic boolean isviewfromobject (View arg0, Object arg1) {return (arg0 = = arg1);} @Overridepublic void Destroyitem (ViewGroup container, int position, object object) {Container.removeview (View) object) ;} @Overridepublic Object Instantiateitem (viewgroup container, int position) {ImageView ImageView = Imageviews.get ( position); Container.addview (ImageView); return ImageView;}}}


And finally there is a main interface test (layout file Nothing)

Activity_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" Match_parent "></RelativeLayout>

Mainactivity.java

Package Com.example.bjnews.activity;import Com.example.bjnews.r;import Android.app.activity;import Android.os.bundle;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main);}}



Welcome interface + Guide into the classic case

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.