The first time Android APP opens the boot interface, this demand is very much. When writing a new project, just want to use, on the Internet to find a demo, did not find the non-satisfactory. So I had to write one by myself, to share, to avoid repeating the wheel after all. Below (though a little ugly)
This is the interface to guide the interface guideactivity, the realization of the idea is simple: the main interface with Framelayout layout, followed by Viewpager loading pictures. The next few dots indicate which interface is currently sliding, because no control is available now, so a inidcatorview is customized, and the layout file is as follows
<framelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Wrap_ Content " android:layout_height=" wrap_content "> <android.support.v4.view.viewpager android:id = "@+id/viewpager" android:layout_width= "match_parent" android:layout_height= "match_parent"/> <cn.guide.indicatorview android:id= "@+id/indicatorview" android:layout_width= "Match_parent " android:layout_height= "45DP" android:layout_marginbottom= "30DP" android:layout_gravity= "bottom| Center_horizontal "/></framelayout>
The custom Indicatorview code is as follows
Public classIndicatorviewextendsview{
private static FinalStringLog_tag= Indicatorview.class. GetName ();
private intMcurrentindicatorindex=0;
private intMindicatorcount=4;
private intmindicatordistance= -; Distance between dots (center distance)
private intMstartdotx;
private intMdoty;
PrivatePaintMpaint;
PublicIndicatorview (Context context) {
Super(Context, NULL);
}
PublicIndicatorview (Context Context, AttributeSet attrs) {
Super(Context, ATTRS);
Mpaint=NewPaint (paint.Anti_alias_flag);
Mpaint. SetStyle (Paint.style.FILL);
}
@Override
protected voidonmeasure(intWidthmeasurespec, intHEIGHTMEASURESPEC) {
intViewwidth = Measurespec.GetSize(WIDTHMEASURESPEC);
intViewheight = Measurespec.GetSize(HEIGHTMEASURESPEC);
intDrawWidth = (Mindicatorcount+1) *mindicatordistance;
Mstartdotx= (viewwidth-drawwidth)/2;
Mdoty= Viewheight/2;
Setmeasureddimension (viewwidth, Viewheight);
}
@Override
protected voidOnDraw(Canvas canvas) {
Super. OnDraw (Canvas);
floatCurrentdotx =Mstartdotx;
for(inti =0; I <Mindicatorcount; i++) {
Currentdotx + =mindicatordistance;
if(i = =Mcurrentindicatorindex) {
Mpaint. SetColor (0x7fff0000);
}Else{
Mpaint. SetColor (0x7f0000ff);
}
Canvas.drawcircle (Currentdotx, Mdoty, Ten, Mpaint);
}
}
Public voidSetindicatorcount(intCount) {
Mindicatorcount= Count;
}
Public voidSetcurindicatorindex(intIndex) {
Mcurrentindicatorindex= Index;
Invalidate ();
}
}
Setindicatorcount is used to set how many points are in total, how many graphs the boot interface will load, Setindicatorcountthe parameters are set to how much you can. The Setcurindicatorindex is used to set the current swipe to which point, and by the way refresh the interface. Because it is relatively simple, so do not do too much introduction
Click to download the source code
The boot interface for the first time Android App is opened