Bug P2
Status Update
Comments
ph...@sprylab.com <ph...@sprylab.com> #2
I face with the same problem. I have different pageMargin in landscape and portrait and when viewpager is scrolled for the more than first position, after rotating device it is shifted.
I beleive the problem is inside onSizeChanged that is called after onConfigurationChanged, it has following code:
if (w != oldw) {
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
}
w always not equals oldw when changing orientation, so recomputeScrollPosition is called, but whit the same values for margin and oldMargin.
This should be fixed.
I beleive the problem is inside onSizeChanged that is called after onConfigurationChanged, it has following code:
if (w != oldw) {
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
}
w always not equals oldw when changing orientation, so recomputeScrollPosition is called, but whit the same values for margin and oldMargin.
This should be fixed.
ph...@sprylab.com <ph...@sprylab.com> #3
[Comment deleted]
ph...@sprylab.com <ph...@sprylab.com> #4
I found the same problem in suport library v4, wrong align happens only when ViewPager has a page margin > 0.
ph...@sprylab.com <ph...@sprylab.com> #5
[Comment deleted]
ph...@sprylab.com <ph...@sprylab.com> #6
The issue is still reproducible in support library v4 (rev. 18).
I managed to fix the issue by importing the source code of ViewPager in my project and modifying from onSizeChanged method the following line:
From:
if (w != oldw) {
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
}
To:
if (w != oldw) {
recomputeScrollPosition(w, oldw, 0, 0);
}
I managed to fix the issue by importing the source code of ViewPager in my project and modifying from onSizeChanged method the following line:
From:
if (w != oldw) {
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
}
To:
if (w != oldw) {
recomputeScrollPosition(w, oldw, 0, 0);
}
jg...@google.com <jg...@google.com>
ph...@sprylab.com <ph...@sprylab.com> #7
I use this little wrapper as a work around for the bug:
ublic class FixedViewPager extends ViewPager {
public FixedViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FixedViewPager(Context context) {
super(context);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w-this.getPageMargin(), h, oldw-this.getPageMargin(), oldh);
}
}
ublic class FixedViewPager extends ViewPager {
public FixedViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FixedViewPager(Context context) {
super(context);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w-this.getPageMargin(), h, oldw-this.getPageMargin(), oldh);
}
}
ph...@sprylab.com <ph...@sprylab.com> #8
Thanks for posting the workaround. Works great. Can't believe this issue still exists after almost 2 years since it's been reported.
ph...@sprylab.com <ph...@sprylab.com> #9
Greats !!
Description
Our articles are one ViewPager and each article has another ViewPager for it's pages.
Basically:
Root
|
-- Article 1
|
-- Page 1
-- Page 2
-- Page 3
-- Article 2
|
-- Page 1
-- Page 2
-- Page 3
Unfortunately the ViewPager does not correctly handle this with nested Fragments which each have menu items. (e.g. a Bookmark item for each page). Paging works as expected but the menu shows all items even from pages which are not visible.