Android Metro Style Launcher Development series The second article

Source: Internet
Author: User
Tags home screen

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 3153255 wrote how to configure the Android development environment, just with text and pictures to show the development of Metro style Launcher preliminary design and product requirements, this article will be on the code to explain how to achieve the corresponding UI effect, 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:
1. Sliding speed control:

This is done by getting Viewpager's scroller, setting some parameters on Scroller, and implementing the Code 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, 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.
@Overridepublic void Startscroll (int startX, int starty, int dx, int dy) {//Ignore received duration, use fixed one I Nstead Super.startscroll (StartX, starty, dx, DY, mduration);} @Overridepublic void Startscroll (int startX, int starty, int dx, int dy, int duration) {//Ignore received duration, u SE fixed one instead super.startscroll (StartX, starty, dx, DY, mduration);}

2. The switch effect between page is implemented :
each screen page between the switch is implemented through the implementation of 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   & Nbsp;private static Float Rotation_factor = 20f;//rotation factor     private static float Alpha_factor = 0.8f;& nbsp;     @Override     public void transformpage (view view, float position) {         if (position <= 1) {//[-1,1]             //Modify The default slide transition to shrink the page as WELL&NBSP;&NBSP;&N Bsp;         if (Position < 0) {                 //view.setrotationy (Position * ROTATION_FACTOR ); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp;   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);                 view.setscalex (Scale_factor *-position + default_scale);                 view.setscaley (SCALE_FACTOR *-position + Default_scale);                 //View.setalpha (alpha_factor *-position + 1.0f);             }        }    } }
    1. Specific effects can be achieved by modifying the rotation and scaling.

    2. Span style= "font-family: ' Microsoft Yahei '" >:

    3. The page section on both sides of the Home screen page can be implemented by setting the Viewpager setpagemargin (int margin) method, as follows:

public class Launcherviewpager extends Viewpager {    public static final int page_limit = 3;&NBSP;&N Bsp;   public Launcherviewpager (Context context) {         This (context, null);     }     public Launcherviewpager (context Context, AttributeSet attrs) {        super (context, attrs);         init (context);    }      private void init (context context) {        this.setpagemargin (- Getresources (). Getinteger (R.integer.portal_viewpager_margin));         This.setoffscreenpagelimit (page_limit);         this.setpagetransformer (True, new Launcherpagetransformer ());         try {     &nBsp;       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) {        } catch (IllegalArgumentException e) {         } catch (Illegalaccessexception e) {         }     }}

The above is the launcher main frame using Viewpager to achieve left and right slide and zoom effect explanation, write bad place also please point out and criticize, "three people will have my teacher", any criticism and suggestions I will have to reply and exchange, can add my number, faster communication. Next blog I will explain each of the screen Cellview implementation, with focus amplification effect, to achieve each focus of the cellview suspension effect and in the XML file flexible configuration links and so on.

Welcome to the personal public platform:Programmer Interaction Alliance(Coder_online), sweep the QR code or search number belowCoder_onlinecan follow,we can communicate online.

Excerpt from:

Android Metro Style Launcher Development series The second article

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: 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.