Objective:
Everyone small partners, again to the weekly update article time, originally was Sunday can send out, this is not to catch the tomb-sweeping day, the Queen said, two days before the Qingming Festival to play with her, only left me Monday afternoon half a day to write a blog, where there is a queen where there is oppression ah have wood! All right, gossip. Less, on a blog (Android Metro style of the Launcher Development series, the second article) said Launcher main framework with Viewpager to achieve, this blog let us say each page of the specific implementation.
Pageradapter:
Launcher the main body Viewpager implementation leads to the Pageradapter,pageradapter is the class in the ANDROID.SUPPORT.V4 package, its subclasses have Fragmentpageradapter, Fragmentstatepageradapter, these two adapter are fragment adapter, because there is no use of fragment here, I only talk about Pageradapter. As for Pageaapter's description, the original version of Google's website is this: Base class providing the adapter to populate pages inside of a viewpager. You'll most likely want to use a more specific implementation of this, such as Fragmentpageradapter or fragmentstatepage Radapter, roughly speaking, Pageradapter is an adapter provided by Viewpager, which allows us to control every view of Viewpager. This is how my pageradapter is implemented:
public class Launcheradapter extends Pageradapter {private arraylist<pageviewitem> mviews; Public Launcheradapter (arraylist<pageviewitem> views) {mviews = views; } @Override public void Destroyitem (View arg0, int arg1, Object arg2) {(Viewpager) arg0). Removeview (mviews. Get (arg1)); } @Override public void Finishupdate (View arg0) {} @Override public int getcount () {if (mviews! = NULL) {return mviews.size (); } return 0; Public View getcurrentview (int currentid) {return mviews.get (CurrentID); } @Override Public Object instantiateitem (View arg0, int arg1) {(Viewpager) arg0). AddView (Mviews.get (arg1)) ; Return Mviews.get (ARG1); } @Override public boolean isviewfromobject (View arg0, Object arg1) {return (arg0 = = arg1); } @Override public void Restorestate (parcelable arg0, ClassLoader arg1) {} @Override public parcelable savEState () {return null; }}
Pageviewitem:
Each view returned by the Pageradapter Getcurrentview method is a custom view, why customize it? Because each icon gets the focus magnified with the icon next to the overlapping part, viewpager each page view is a framelayout, when the view is drawn in a certain sequence, You will encounter the focus when the view is magnified and the effect is partially pressed by the view next to it, you cannot avoid this problem if you do not change the view drawing order.
As shown, figure one shows that the focus view zooms in, changing the rendering order. Changing the drawing order is actually rewriting ViewGroup's getchilddrawingorder (int childCount, int i) method, and each time it is drawn, it returns the index in the ViewGroup where Focusview is located.
Cellview:
As shown, each square view I'm here is called Cellview, which is also a custom view, which is designed primarily to achieve:
1, Zoom in and lose focus when the focus to reduce the effect, here is the application of property animation, Viewpropertyanimator can be obtained through the view of the animate () method, the specific animation is implemented as follows:
Mpropertyanimator.scalex ((width + mscalex)/width) . ScaleY ((height + mscaley)/height). Setduration (Duration) . Setinterpolator (New Decelerateinterpolator ()) . Start ();
2, in the XML file flexible configuration of some Cellview properties, such as click Open Application, the display of the icon to get the address, focus x, y amplification value, etc., cellview corresponding attribute definition Attrs.xml file as follows:
<?xml version= "1.0" encoding= "Utf-8"?><resources> <declare-styleable name= "Launcher_scaleview" > <attr name= "ParentID" format= "integer"/> <attr name= "Resurl" format= "string"/> <attr name = "ResType" format= "integer"/> <attr name= "Isrightedge" format= "boolean"/> <attr name= "islefted GE "format=" boolean "/> <attr name=" Istopedge "format=" boolean "/> <attr name=" Isbottomedge "for Mat= "boolean"/> <attr name= "ScaleX" format= "integer"/> <attr name= "ScaleY" format= "integer"/& Gt <attr name= "PackageName" format= "string"/> <attr name= "Activityname" format= "string"/> <att R name= "Intentkey" format= "string"/> <attr name= "Intentvalue" format= "string"/> <attr name= "fo Custype "format=" integer "/> </declare-styleable></resources>
3.The implementation of the remote control to move focus without focus confusion, in the development of remote control applications, a big problem is the focus on the movement of focus confusion, basically apply UI bug at least half of the focus bug, this application I to prevent the focus of confusion defined Cellview boundary properties, The above XML file is Isxxedge, so that when the focus moves to the boundary, you can switch between the page and other processing, to prevent the focus from entering each page when the confusion.
Here's a look at the specific effect of the implementation:
Summary: The above is the Metro Style Launcher implementation, I used three blog to explain the application, all the effect of the implementation are their own groping, there should be a better way to achieve, we can communicate a lot of their views, you can also pay attention to my number Coder_online , above thank you!
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.
Android Metro Style Launcher development Series third