Android Metro Style Launcher Development series The second article

Source: Internet
Author: User

Preface:

Dear friends, please forgive me for so long to start writing this series of the second blog, no way to busy new product release, good nonsense not to say, first review: In my previous blog Android Metro style Launcher development series The first article wrote how to configure the Android development environment, Just using text and pictures to show the initial design and product requirements for developing Metro style launcher, this article will explain how to implement the corresponding UI effect from the code, OK, storytelling!


Launcher Main Framework implementation:

Launcher Main Frame I choose is familiar with the Viewpager control, because Viewpager can easily do pager between the switch animation, animation can be customized, so easy to get rid of the various effects slide out of the screen, you can also control the speed of switching, This makes it easy to achieve the following effects:


650) this.width=650; "src=" http://img.blog.csdn.net/20150329193310127 "style=" border:none; "/>


1. Sliding speed control:

this is viewpager by getting scroller, Re-set some parameters on the scroller, the specific implementation of the code is as follows:

Field Scroller = ViewPager.class.getDeclaredField ("Mscroller"); Scroller.setaccessible (true); Interpolator interpolator = new Linearinterpolator ();//Set Accelerator Viewpagerscroller Scroller = new Viewpagerscroller (context,interpolator);//Reset Viewpager Scrollerscroller.set (this, scroller);

In the above code is used in the Viewpagerscroller.java, in the Viewpagerscroller is set as follows, where the mduration variable is a custom animation time, this you can set the length of time according to their own animation effect, I define this as 500 milliseconds.

     @Override     public  Void startscroll (Int startx, int starty, int dx, int dy)  {         // ignore received duration, use fixed  one instead        super.startscroll (StartX, startY,  dx, dy, mduration);    }     @Override      public void startscroll (int startx, int starty, int dx,  Int dy, int duration)  {        // ignore  received duration, use fixed one instead         super.startscroll (startx, starty, dx, dy, mduration);     } 

2.Page switch effect between the implementation:

Each screen page between the switch is implemented by implementing the Viewpager.pagetransformer interface, the specific explanation of this interface I do not introduce here, you can refer to Google official documents: Using Viewpager for screen Slides. My implementation is as follows:

class launcherpagetransformer implements viewpager.pagetransformer {     private static float DEFAULT_SCALE = 1.0f;    private  static float scale_factor = 0.30f;//  Scaling Factor  0.50f    private  static float ROTATION_FACTOR = 20f;//  rotation Factor     private  static float alpha_factor = 0.8f;     @Override      Public void transformpage (view view, float position)  {         if  (position <= 1)  { // [-1,1]             // Modify the default slide  transition to shrink the page as well             if  (position < 0)  {                 // view.setrotationy (Position * rotation_factor);                 view.setscalex (Scale _factor * position + default_scale);                 view.setscaley (Scale_factor * position + default _scale);                 //  view.setalpha (alpha_factor * position + 1.0f);             } else {                 // view.setrotationy (Position * rotation_factor);      &Nbsp;          view.setscalex (SCALE_FACTOR * - Position + default_scale);                 view.setscaley (Scale_factor * -position + default_scale);                 //  View.setalpha (alpha_factor * -position + 1.0f);             }        }    }}

Specific effects can be achieved by modifying the rotation and scaling.

3. Left and right side page hover implementation:

The

Home Screen page side page display can be implemented by setting the Viewpager setpagemargin (int margin) method, with the following code: < span>

Public class launcherviewpager extends viewpager {    public  static final int PAGE_LIMIT = 3;    public  Launcherviewpager (Context context)  {        this (Context,  null);     }    public launcherviewpager (Context  Context, attributeset attrs)  {        super (context, &NBSP;ATTRS);         init (context);    }     private void init (Context context)  {         this.setpagemargin (-getresources (). Getinteger (R.integer.portal_viewpager_margin));         this.setoffscreenpagelimit (Page_limit);         this.setpagetransformer (True,&nbsP;new launcherpagetransformer ());        try {             Field Scroller =  ViewPager.class.getDeclaredField ("Mscroller");             scroller.setaccessible (True);             interpolator interpolator = new linearinterpolator ();             ViewPagerScroller scroller = new  Viewpagerscroller (context,                     interpolator);             scroller.set (This, scroller);         } catch   (nosuchfieldexception e) &NBSP;{&NBSP;&NBSP;&NBsp;     } catch  (illegalargumentexception e)  {         } catch  (illegalaccessexception e)  {         }    }}

          Summary: The above is launcher the main frame using Viewpager to achieve left and right slide and zoom effect explained, Write bad place also please point out and criticize correct, "three people will have my teacher", any criticism and suggestions I will have to reply and exchange, can add my number, faster communication.


The first time to get blog update reminders, as well as more technical information sharing, welcome to the personal public platform: Programmer Interaction Alliance (coder_online), sweep the QR code below or search number Coder_online can pay attention to, we can communicate online.

650) this.width=650; "Src=" http://img.blog.csdn.net/201 50323142905787 "style=" Border:none;color:rgb (51,51,51); font-family:arial;font-weight:bold;line-height:26px; White-space:normal;background-color:rgb (255,255,255); "/>

This article is from the "8646004" blog, please be sure to keep this source http://8656004.blog.51cto.com/8646004/1626571

Android Metro Style Launcher Development series The second 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.