Function points: Infinite carousel, Cue point follow, click Response. Implementation ideas:
1, the indicator points follow, indicating that the point is dynamically added by the code, the quantity is determined by the number of pictures.
In the Viewpager page change listener, set the state selector of the point to enable, the current page, setenable (TRUE), the non-current page is set to False. Since the picture is obtained from the network, the number is variable, so you cannot use switch to write dead, you need to set the variable record current and previous. The code is as follows:
Lladdpoint linear layout for adding indicator points
Preposition is the previous position, set to 0,newposition as the current position when initialized
int newposition =position%imageviews.size () ;/ /Use maximum value for infinite carousel, so modulo is required.
lladdpoint.getchildat (newposition). setenabled (true) lladdpoint.getchildat (preposition). setenabled ( False) ;
preposition=newposition
2. Turn off the carousel diagram in the OnDestroy method of activity
3, click the response in the Viewpager adapter in the Instantiateitem method set, because the picture for the network acquisition, so you can set the ID of the way to set the Click event code:
@Override
Public ObjectInstantiateitem (ViewGroup container, final int position) {
ImageView IV =Imageviews.get (Position%Imageviews.size ());
Container.addview (iv);
//Set the Click event of the picture in this method
Iv.setonclicklistener (New View.onclicklistener () {
@Override
public voidOnClick (View v) {
//Handling Jump Logic
Toast.< Span style= "font-style:italic;" >maketext (Carouselactivity. This, " was ordered. "+position% Imageviews.size () ,toast. Length_short). Show () ;
}
) ;
return Iv;
}
4, the indicator point using shape to draw the following is the size of 5DP, solid gray dots.
<shapexmlnsAndroid= "http://schemas.android.com/apk/res/android"
android:shape= >
<solid Span style= "color: #9876aa;" >android:color=/>
<size android :height=android :width=/>
</SHAPE>
Summary of AD carousel in Android