android - Implementing a custom indicator with ViewPageIndicator - How can I do it to a gallery? -
i'm working on project , managed point can show images in gallery sort of style using pageradapter. want add indicator image on screen , figure vpi me out - problem i'm new code , don't know how implement it, help?
here's gif of want achieve - green line indicator: http://imgur.com/ggygy8i
i made simpler version of project fit in post, here is:
imageadapter.java
package com.exp.viewpagersstest1; import android.content.context; import android.support.v4.view.pageradapter; import android.support.v4.view.viewpager; import android.view.view; import android.view.viewgroup; import android.widget.imageview; public class imageadapter extends pageradapter { context sscontext; private int[] ssimages = new int[] { r.drawable.splash1,r.drawable.splash2, r.drawable.splash3 }; imageadapter(context sscontext) { this.sscontext = sscontext; } @override public int getcount() { return ssimages.length; } @override public boolean isviewfromobject(view ssview, object ssobject) { return ssview == ((imageview) ssobject); } @override public object instantiateitem(viewgroup sscontainer, int ssposition) { imageview ssimageview = new imageview(sscontext); ssimageview.setscaletype(imageview.scaletype.fit_xy); ssimageview.setimageresource(ssimages[ssposition]); ((viewpager) sscontainer).addview(ssimageview, 0); return ssimageview; } @override public void destroyitem(viewgroup sscontainer, int ssposition, object ssobject) { ((viewpager) sscontainer).removeview((imageview) ssobject); } }
sstest.java
package com.exp.viewpagersstest1; import android.app.activity; import android.os.bundle; import android.support.v4.view.viewpager; import android.view.menu; public class sstest extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_sstest); viewpager ssviewpager = (viewpager) findviewbyid(r.id.ss_view_pager); imageadapter ssadapter = new imageadapter(this); ssviewpager.setadapter(ssadapter); } @override public boolean oncreateoptionsmenu(menu menu){ // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.sstest, menu); return true; }
activity_sstest.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".sstest" > <android.support.v4.view.viewpager android:id="@+id/ss_view_pager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:adjustviewbounds="true" /> </relativelayout>
viewpagersstest1 manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.exp.viewpagersstest1" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="17" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.exp.viewpagersstest1.sstest" android:label="@string/app_name" android:theme="@style/theme.sherlock.noactionbar" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
thanks in advance replies.
was more simple expected, needed add following xml:
<com.viewpagerindicator.underlinepageindicator android:id="@+id/pageindic" android:layout_height="3dp" android:layout_width="fill_parent" android:layout_alignparentbottom="true" app:selectedcolor="#ef4154"/>
and following oncreate under java file:
underlinepageindicator pageindicator = (underlinepageindicator) findviewbyid(r.id.pageindic); pageindicator.setviewpager(ssviewpager);
Comments
Post a Comment