My Android Case-launch page

Source: Internet
Author: User

The 2015 Android Case tour

Case 10: Start Page

Role:
1. Advertise, put a few creative or good-looking pictures to attract the eye
2. Data preparation, pre-loading some data, creating a table or something

Knowledge Points:

    1. The use of the Viewpager control.
    2. Invocation of the corresponding listener event
    3. Storing identities through sharedpreferences

Documents involved:

    1. Res->layout->activity_main.xml Main interface Layout file
    2. Res->layout->splash.xml Welcome Interface Layout File
    3. Res->layout->guide Boot Interface Layout file
    4. Res->layout->one (.) Boot interface layout file
    5. Res->src->package->mainactivity.java Main interface
    6. Res->src->package->splashactivity.java Welcome Interface
    7. Res->src->package->guideactivity.java Boot Interface
    8. Res->src->package->viewpageradapter.java Adapter

On the layout file, this time the main reference is the ImageView control, used to show the effect, there is no more explanation.
The main point of view is the use of Viewpager and Viewpageradapter
Guideactivity.java

 Public  class guideactivity extends actionbaractivity  implements  Viewpager. Onpagechangelistener {    PrivateViewpager VP;PrivateViewpageradapter Vpadapter;Privatelist<view> views;//Bottom small dot picture    PrivateImageview[] dots;//Record the currently selected location    Private intCurrentindex;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.guide);        Initview ();    Initdots (); }Private void Initview() {Layoutinflater inflater = Layoutinflater.from ( This); views =NewArraylist<view> (); Views.add (Inflater.inflate (R.layout.what_new_one,NULL)); Views.add (Inflater.inflate (R.layout.what_new_tow,NULL)); Views.add (Inflater.inflate (R.layout.what_new_three,NULL)); Views.add (Inflater.inflate (R.layout.what_new_four,NULL));//Initialize adapterVpadapter =NewViewpageradapter (views, This);        VP = (Viewpager) Findviewbyid (r.id.guidepages);        Vp.setadapter (Vpadapter); Vp.setonpagechangelistener ( This); }Private void Initdots() {LinearLayout LL = (linearlayout) Findviewbyid (R.ID.LL); Dots =NewImageview[views.size ()];//loop to get the dot picture         for(inti =0; I < views.size ();            i++) {Dots[i] = (ImageView) ll.getchildat (i); Dots[i].setenabled (true);//are set to gray} Currentindex =0; Dots[currentindex].setenabled (false);//Set to white, select State}Private void Setcurrentdot(intPosition) {if(Position <0|| Position > Views.size ()-1|| Currentindex = = position) {return; } dots[position].setenabled (false); Dots[currentindex].setenabled (true);    Currentindex = position; }//Called when sliding state changes    @Override     Public void onpagescrollstatechanged(intarg0) {}//Called when the current page is being slid    @Override     Public void onpagescrolled(intARG0,floatArg1,intARG2) {}//Called when a new page is selected    @Override     Public void onpageselected(intARG0) {//Set bottom dot check stateSetcurrentdot (arg0); }

Viewpageradapter.java

 Public  class viewpageradapter extends pageradapter {    //file name for storing data    Private Static FinalString Sharedpreferences_name ="First_pref";//Interface list    Privatelist<view> views;PrivateActivity activity; Public Viewpageradapter(list<view> views,activity Activity) { This. views = views; This. activity = activity; }//Destroy the interface of Arg1 location    @Override     Public void Destroyitem(View arg0,intArg1, Object arg2) {((Viewpager) arg0). Removeview (Views.get (arg1)); }//Determines whether the interface is generated by the object    @Override     Public Boolean Isviewfromobject(View view, Object parent) {return(view = = parent); }//Get current interface number    @Override     Public int GetCount() {if(Views! =NULL) {returnViews.size (); }return 0; }@Override     PublicObjectInstantiateitem(View view,intpostion) {(Viewpager) view). AddView (Views.get (postion),0);if(postion = = Views.size ()-1) {ImageView Mstartimagebutton = (ImageView) View.findviewbyid (R.id.iv_start); Mstartimagebutton.setonclicklistener (NewView.onclicklistener () {@Override                 Public void OnClick(View v)                    {setguide ();                GoHome ();        }            }); }returnViews.get (postion); }Private void GoHome() {Intent Intent =NewIntent (activity, mainactivity.class);       Activity.startactivity (Intent);   Activity.finish (); }Private void Setguide() {Sharedpreferences preferences = Activity.getsharedpreferences (Sharedpreferences_name, context.mode_private);       Sharedpreferences.editor Editor = Preferences.edit (); Editor.putboolean ("Isfirstin",false);   Editor.commit (); }}

Of course, also take into account the full screen, Androidmanifest.xml file activity in the Declaration, or the final effect is not very good-looking.
Several other ways of realizing it, you can learn about
First type: Viewflipper + gesturedetector

The second type: Activitygroup + gesturedetector

The third type: Viewflow (open source project)

My Android Case-launch page

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.