Im not able to load the page with circlepageindicator. This is the xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/bg2" android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout android:layout_width="220dp"
android:orientation="vertical" android:layout_gravity="center_horizontal"
android:layout_height="32dp" android:layout_marginTop="32dp">
<android.support.v4.view.ViewPager
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/myfivepanelpager" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
java file
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyPagerAdapter adapter=new MyPagerAdapter();
ViewPager myPager=(ViewPager)findViewById(R.id.myfivepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(2);
CirclePageIndicator titleIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
titleIndicator.setViewPager(myPager);
}
jake wharton project has been added to the library. It doesnt give any error while building, but not loading the page. whats wrong?
Your
ViewPager
is set tomatch_parent
which will prevent any other view in the container from showing. Set theViewPager
height to0dp
withandroid:layout_weight="1"
.The container is also hard-coded to
32dp
which is extremely tiny and likely will not hold both the pager and indicator comfortably.Missing to add
myIndicator.onPageScrolled(myViewPager.getCurrentItem(), 0, 0);
may also cause CirclePageIndicator not working.eg:
myViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { myIndicator.onPageScrolled(myViewPager.getCurrentItem(), 0, 0); } });