Implementation of sliding point in Android

Source: Internet
Author: User

<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 );

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.