我在冰激凌三明治上遇到了Astuetz Viewpager的小问题。问题是,当滚动页面时,页面指示器和日期不会消失/改变颜色。同样的寻呼机,在预装蜂窝的设备上,工作起来就像一个护身符。有没有人面临同样的问题?
发布于 2012-05-16 16:28:19
我找到了一个解决方案。
我一直在分析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());
}
}https://stackoverflow.com/questions/10596792
复制相似问题