我在 Icecream Sandwich 上遇到了 Astuetz Viewpager 的一个小问题。 问题是,在滚动页面时,页面指示器和日期不会消失/改变颜色。 同样的寻呼机,在 pre-honeycomb 设备上,工作起来就像一个魅力。 有人遇到同样的问题吗?
最佳答案
我找到了解决方案。
我一直在分析 Astuetz viewpager 库,我发现在滚动页面时不会调用包含日期和彩色底部边框的 TextView 的 onDraw 方法。我们需要对该扩展 TextView 的父 onLayout 方法调用 invalidate 方法。
像这样更改 ViewPagerTabs 类(在 for 循环中添加 tab.invalidate())
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
final int center = this.getMeasuredWidth() / 2;
// At this position, the centered tab will be highlighted via
// ViewPagerTab.setCenterPercent(int percent)
final int highlightOffset = this.getMeasuredWidth() / 5;
// lay out each tab
for (int i = 0; i < count; i++) {
final ViewPagerTab tab = (ViewPagerTab) getChildAt(i);
tab.invalidate();
final int tabCenter = tab.layoutPos + tab.getMeasuredWidth() / 2;
int diff = Math.abs(center - tabCenter);
if (diff <= highlightOffset) {
final int x1 = highlightOffset;
final int y = (int) 100 * diff / x1;
tab.setCenterPercent(100 - y);
} else {
tab.setCenterPercent(0);
}
tab.layout(tab.layoutPos, this.getPaddingTop(), tab.layoutPos + tab.getMeasuredWidth(), this.getPaddingTop()
+ tab.getMeasuredHeight());
}
}
关于android - Stutz viewpager on android Ice Cream Sandwich ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10596792/