Bug P3
Status Update
Comments
go...@gmail.com <go...@gmail.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.
go...@gmail.com <go...@gmail.com> #3
[Comment deleted]
zh...@gmail.com <zh...@gmail.com> #4
I found the same problem in suport library v4, wrong align happens only when ViewPager has a page margin > 0.
gu...@gmail.com <gu...@gmail.com> #5
[Comment deleted]
gu...@gmail.com <gu...@gmail.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);
}
fl...@gmail.com <fl...@gmail.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);
}
}
ja...@gmail.com <ja...@gmail.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.
[Deleted User] <[Deleted User]> #9
Greats !!
en...@google.com <en...@google.com>
st...@gmail.com <st...@gmail.com> #10
This bug is not obsolete. It is reproducible with support library v23 on API 19 and 22 (haven't been able to try 23).
Workaround in post #6 still works.
Workaround in post #6 still works.
au...@google.com <au...@google.com>
au...@google.com <au...@google.com>
sm...@gmail.com <sm...@gmail.com> #11
Issue on ViewPager :- Padding is different for Portrait and Landscape. Scroll few pages and do orientation change. ViewPager pages are not aligned properly.
pa...@gmail.com <pa...@gmail.com> #12
7 years later and still the same problem with androidx viewpager 1.0.0
an...@move.com <an...@move.com> #13
8 years later and still the same issue with androidx viewpager2
jg...@google.com <jg...@google.com> #14
Re
Description
2. Run it on a device or in the emulator
3. Scroll a few pages
4. Change the orientation
Expected: View pager content properly aligned
Actual: The current page is slightly offset (see attached screenshot). Scrolling from there brings it back to the right place
This doesn't happen if the target SDK is set to 15 instead of 10 (but maybe then it uses the native version?). It did not happen when the view pager was first introduced to the support library, but happens systematically in at least version 10.