First of all, this is the next effect chart:
Google offers V4 packs, Viewpager
In the layout file, first add the <android.support.v4.view.ViewPager/> control, this is only the area of the carousel
In the layout file, lay out the title Description section
Linear layout, vertical arrangement, background color black translucent, this layout and above Viewpager bottom align layout_alignbottom= "@id/xxx"
<TextView/> Center Display,
The smaller part, the first empty Linearlayout,id is ll_points in the code to populate it
Get Viewpager Object
Call the Viewpager object's Setadapter () method, Parameter: Pageradapter object
Because Pageradapter is an abstract class, define a Mypageradapter inheritance Pageradapter, implement the following methods
Rewrite the GetCount () method to return the number of carousel
Overrides the Isviewfromobject () method, returns a Boolean value,
Overrides the Instantiateitem () method to add the current View object to the ViewGroup object, returning the current object
Overrides the Destroyitem () method to delete the view of the specified location (position) from the current container
Toggle Description Title String
Define a string[] array, save the caption
Call the Viewpager object's Setonpagerchangelistener () method, Parameter: Onpagerchangelistener object
Anonymous inner class implementation, overriding the following methods
Onpageselected () method, page switch after the call, passed in parameters, int index
Onpagescrolled () method, when the page is scrolling
Onpagescrollstatechanged () method, when the page scrolling state changes
Small icon Section
Create a new two shape file and draw two original points using XML
Add node <shape>, set shape to prototype android:shape= "Oval"
Add Dimension node <size>, set width, height, android:width= "" android:height= ""
Add a color node <solid>, set the color android:color= ""
Normally, gray dot, focus time, white dot, two XM file color is not the same
Point.xml
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:shape=" Oval ">
<size
android:height=" 4DP "
android:width=" 4DP "/>
<solid android:color= "#aaffffff"/>
Point_write.xml
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:shape=" Oval ">
<size
android:height=" 4DP "
android:width=" 4DP "/>
<solid android:color= "#ffffffff"/>
Create a new selector file, when the picture enabled when the white point, not when the gray point, different states different pictures
Add <selector> Node
Add <item> node, set picture Properties android:drawable= "" Setting State android:enabled= "True|false"
Point_selector.xml
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android >
<item android:drawable= "@drawable/point" android:state_enabled= "false" ></item>
<item android:drawable= "@drawable/point_write" android:state_enabled= "true" ></item>
Cycle the number of large pictures, create ImageView objects,
Call ImageView Object Setimageresource () method, set resource, parameter: Selector file
Invokes the Setlayoutparams () method of the ImageView object, adding some margin values to the small icon ImageView object, Parameter: Layoutparams object, Gets the Linearlayout.layoutparams object, invokes the RightMargin () method of the Layoutparams object, and sets the margin value
Invokes the SetEnabled () method of the ImageView object, setting whether it is available, parameters: Boolean
Gets the LinearLayout object, calls the LinearLayout object's AddView () method, and fills in the view of the small icon, parameters: ImageView Object
Default first is focus, as the picture slides, the focus changes
Package Com.tsh.myviewpager;
Import java.util.ArrayList;
Import java.util.List;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.support.v.view.pageradapter;
Import Android.support.v.view.viewpager;
Import Android.support.v.view.viewpager.onpagechangelistener;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.TextView; public class Mainactivity extends activity {private Viewpager vp_banner; private linearlayout ll_points; private TextView
Tv_title;
Private list<view> banners;
Private string[] Titles=new string[]{"News Headlines", "News headlines", "News Headlines"};
Private list<imageview> points=new arraylist<imageview> (); @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
Initialize Vp_banner = (Viewpager) Findviewbyid (R.id.vp_banner);
Ll_points = (linearlayout) Findviewbyid (r.id.ll_points);Tv_title = (TextView) Findviewbyid (r.id.tv_title);
Banner Part banners = new arraylist<> ();
ImageView img = new ImageView (this);
Img.setimageresource (R.DRAWABLE.A);
Banners.add (IMG);
ImageView img = new ImageView (this);
Img.setimageresource (r.drawable.b);
Banners.add (IMG);
ImageView img = new ImageView (this);
Img.setimageresource (R.DRAWABLE.C);
Banners.add (IMG);
Small icon ll_points= (linearlayout) Findviewbyid (r.id.ll_points); for (int i=;i<banners.size (), i++) {ImageView image=new imageview (this); Image.setimageresource (R.drawable.point_
selector);
Linearlayout.layoutparams params=new Linearlayout.layoutparams (,);
params.rightmargin=;
Image.setlayoutparams (params);
Ll_points.addview (image); if (i==) {image.setenabled (true);}
else{image.setenabled (false);} points.add (image);
//Set Adapter Vp_banner.setadapter (new Mypageradapter ()); Vp_banner.setonpagechangelistener (New Onpagechangelistener () {@Override public void onpageselected (int arg) {tv_
Title.settext (Titles[arg]); Small icon processing for (ImAgeview point:points) {point.setenabled (false);} points.get (Arg). SetEnabled (True); @Override public void onpagescrolled (int arg, float arg, int arg) {//TODO auto-generated method stub} @Override publi
c void onpagescrollstatechanged (int arg) {//TODO auto-generated Method stub}}); Private class Mypageradapter extends Pageradapter {@Override public void Destroyitem (ViewGroup container, int position, Object) {Container.removeview (Banners.get (position));} @Override public Object Instantiateitem (viewgroup container, int position) {Container.addview (Banners.get (position)); return banners.get (position); @Override Public int GetCount () {return banners.size ():} @Override public boolean isviewfromobject (View arg, Object Arg) {return arg = =
Arg }
}
}
The above is a small set to introduce the Android development of the sliding picture of the title focus of the relevant knowledge, I hope to help you!