Android ViewPagerIndicator无法刷新
首先,我在以下链接中使用ViewPagerIndicator来显示我的view-pager中的视图计数: http://viewpagerindicator.com/
first of all I am using the ViewPagerIndicator from the following link to display the count of views inside of my view-pager: http://viewpagerindicator.com/
我只使用了CirclePageIndicator和通常的代码...我的XML看起来像这样:
I used a CirclePageIndicator with just the usually code... my XML looks like this:
<FrameLayout
android:id="@+id/detailFragment"
android:name="detailFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/pageIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fillColor="@android:color/black"
app:pageColor="@android:color/white"
app:radius="6dp"
app:strokeColor="@android:color/darker_gray"
app:strokeWidth="1dp" />
</FrameLayout>
我的用于设置适配器和指示器的Java代码也没什么特别的,并将在下面发布(来自我的活动类)
My java code to set the adapter and the indicator is also nothing special and will be posted below (from my activity class)
final ViewPager pager = (ViewPager) this.findViewById(R.id.viewpager);
final DutyViewPager adapter = new DutyViewPager(this.getFragmentManager(), pkid, pager.getAdapter());
pager.setAdapter(adapter);
final CirclePageIndicator cIndicator = (CirclePageIndicator) this.findViewById(R.id.pageIndicator);
cIndicator.setViewPager(pager);
问题:可以说,我们有一个导航,其中两个元素链接到两个不同的ViewPagerAdapter.第一个元素链接到适配器 A ,显示 2个片段,第二个元素链接到适配器 B ,显示一个 3个片段的数量.单击第一个元素后,我的视图将使用适配器 A 更新,从适配器中加载第一个片段并显示 2个圆圈作为适配器计数-因此,基本上,一切都与预计到现在.单击第二个元素后,我的视图正在寻找适配器 B ,,但是该视图仍仅显示2个圆圈,,所以我猜指示器没有更新或发生了什么变化...当我滑动到右侧以显示适配器B 中的下一个片段时,此问题已解决.(刷卡后显示3个圆圈)
Problem: Lets say, we have a navigation with two elements linked to two different ViewPagerAdapter. The first element links to the adapter A, which displays a count of 2 fragments and the second element links to the adapter B, which displays a count of 3 fragments. After clicking at the first element my view will update with adapter A, loading the first fragment from the adapter and showing 2 circles as adapter-count - so basicly, everything is as expected till now. After clicking at the second element, my view is lodaing the adapter B, but the view is still showing only 2 circles, so I guess the indicator is not updating or something... the problem is fixed at the moment I swipe to the right side to display the next fragment in adapter B. (it shows 3 circles after swiping)
只是想知道是我还是其他人也遇到了这个问题(以及解决方案)?
Just wondering if it´s just me or if someone else got this problem (and a solution) as well?
在查看CirclePageIndicator.java中的onDraw方法之后,我遇到了同样的问题,我发现这是由于将snap设置为true引起的.将snap更改为false后,一切看起来都很好.
I had the same problem before, after looking into the onDraw method in CirclePageIndicator.java, I found that it was caused by setting snap to true. After changing snap to false, everything looks good.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="StyledIndicators" parent="Theme.Light">
<item name="vpiCirclePageIndicatorStyle">@style/CustomCirclePageIndicator</item>
</style>
<style name="CustomCirclePageIndicator">
<item name="snap">false</item>
</style>
</resources>