Android CirclePageIndicator not working

不羁岁月 提交于 2020-01-11 07:47:11

问题


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?


回答1:


Your ViewPager is set to match_parent which will prevent any other view in the container from showing. Set the ViewPager height to 0dp with android: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.




回答2:


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); } });



来源:https://stackoverflow.com/questions/9963517/android-circlepageindicator-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!