android - how to add dot indicator and circular way transition in image slider using ViewPager -
here make simple slider want know how apply simple dot indicator in code .and thing want apply how apply circular transition in image slider ..
here code:
imageslider.java
import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.app.activity; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.menu; import android.view.view; import android.widget.adapterview; public class imageslider extends activity { viewpager viewpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_imageslider); viewpager = (viewpager) findviewbyid(r.id.viewpager); pageradapter adapter = new sliderimage(imageslider.this); viewpager.setadapter(adapter); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu, menu); return true; } }
sliderimage.java
import android.app.activity; import android.content.context; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.linearlayout; import android.widget.textview; /** * created administrator on 27/05/2016. */ public class sliderimage extends pageradapter{ context context; int[] imageid = {r.drawable.img1, r.drawable.img2, r.drawable.img3, r.drawable.img4, r.drawable.img5}; public sliderimage(context context){ this.context = context; } @override public object instantiateitem(viewgroup container, int position) { // todo auto-generated method stub layoutinflater inflater = ((activity)context).getlayoutinflater(); view viewitem = inflater.inflate(r.layout.image_item, container, false); imageview imageview = (imageview) viewitem.findviewbyid(r.id.imageview); imageview.setimageresource(imageid[position]); //textview textview1 = (textview) viewitem.findviewbyid(r.id.textview1); //textview1.settext("hi"); ((viewpager)container).addview(viewitem); return viewitem; } @override public int getcount() { // todo auto-generated method stub return imageid.length; } @override public boolean isviewfromobject(view view, object object) { // todo auto-generated method stub return view == ((view)object); } @override public void destroyitem(viewgroup container, int position, object object) { // todo auto-generated method stub ((viewpager) container).removeview((view) object); } } **activity_imageslider.xml** <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <android.support.v4.view.viewpager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="200dp" /> </linearlayout> **image_item.xml** <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <imageview android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="300dp" /> </linearlayout>
give me brief code details :
Comments
Post a Comment