In Progress
Status Update
Comments
al...@google.com <al...@google.com>
al...@google.com <al...@google.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.
sp...@google.com <sp...@google.com>
sp...@google.com <sp...@google.com> #4
I found the same problem in suport library v4, wrong align happens only when ViewPager has a page margin > 0.
sp...@google.com <sp...@google.com> #5
[Comment deleted]
al...@google.com <al...@google.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);
}
ze...@gmail.com <ze...@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);
}
}
au...@google.com <au...@google.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.
sp...@google.com <sp...@google.com> #9
Greats !!
au...@google.com <au...@google.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.
sp...@google.com <sp...@google.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.
sp...@google.com <sp...@google.com> #12
7 years later and still the same problem with androidx viewpager 1.0.0
Description
If you are no longer supporting this library, then follow