<Linearlayout
Android: Id = "@ + ID/viewgroup"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_alignparentbottom = "true"
Android: layout_marginbottom = "30dp"
Android: gravity = "center_horizontal"
Android: Orientation = "horizontal">
</Linearlayout>
// Group is the linearlayout in R. layou. Main that is responsible for wrapping small dots.
Group = (viewgroup) Main. findviewbyid (R. Id. viewgroup );
Viewpager = (viewpager) Main. findviewbyid (R. Id. guidepages );
For (INT I = 0; I <pageviews. Size (); I ++ ){
Imageview = new imageview (guideviewdemoactivity. This );
Imageview. setlayoutparams (New layoutparams (20, 20 ));
Imageview. setpadding (20, 0, 20, 0 );
Imageviews [I] = imageview;
If (I = 0 ){
// The first image is selected by default.
Imageviews [I]. setbackgroundresource (R. drawable. page_indicator_focused );
} Else {
Imageviews [I]. setbackgroundresource (R. drawable. page_indicator );
}
Group. addview (imageviews [I]);
}
@ Override
Public void onpageselected (INT arg0 ){
For (INT I = 0; I <imageviews. length; I ++ ){
Imageviews [arg0]
. Setbackgroundresource (R. drawable. page_indicator_focused );
If (arg0! = I ){
Imageviews [I]
. Setbackgroundresource (R. drawable. page_indicator );
}
}
}
<Linearlayout Android: layout_width = "wrap_content"
Android: layout_height = "35dip"
Android: layout_gravity = "bottom | center_horizontal"
Android: gravity = "center">
<Linearlayout
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: gravity = "center">
<View
Android: Id = "@ + ID/dot01"
Style = "@ style/dot_style"
Android: Background = "@ drawable/dot_focused"/>
<View
Android: Id = "@ + ID/dot02"
Style = "@ style/dot_style"
Android: layout_marginleft = "10dip"/>
<View
Android: Id = "@ + ID/dot03"
Style = "@ style/dot_style"
Android: layout_marginleft = "10dip"/>
<View
Android: Id = "@ + ID/dot04"
Style = "@ style/dot_style"
Android: layout_marginleft = "10dip"/>
</Linearlayout>
</Linearlayout>
Dot_style.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "dot_style">
<Item name = "Android: layout_width"> 5dip </item>
<Item name = "Android: layout_height"> 5dip </item>
<Item name = "Android: background"> @ drawable/dot_normal </item>
<Item name = "Android: layout_marginleft"> 1.5dip </item>
<Item name = "Android: layout_marginright"> 1.5dip </item>
</Style>
</Resources>
<? XML version = "1.0" encoding = "UTF-8"?> Dot_focused
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Shape = "Oval">
<Solid Android: color = "# ffffff"/>
<Corners Android: radius = "5dip"/>
</Shape>
<? XML version = "1.0" encoding = "UTF-8"?> Dot_normal
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Shape = "Oval">
<Solid Android: color = "# aaffffff"/>
<Corners Android: radius = "5dip"/>
</Shape>
Private void initdots (){
Listdots = new arraylist <View> ();
Listdots. Add (findviewbyid (R. Id. dot01 ));
Listdots. Add (findviewbyid (R. Id. dot02 ));
Listdots. Add (findviewbyid (R. Id. dot03 ));
Listdots. Add (findviewbyid (R. Id. dot04 ));
}
(View) listdots. Get (position). setbackgroundresource (R. drawable. dot_focused );
(View) listdots. Get (oldposition). setbackgroundresource (R. drawable. dot_normal );