Reputation: 1051
I am doing an app with gallery with showing a few images, when I scroll the images, they move and jump after a certain point. How do I make them smooth? Any sample code would be of great help.
Upvotes: 3
Views: 2551
Reputation: 228
I managed to solve this problem by overriding the onLayout() method in the Gallery parent and then ignoring any calls where the changed flag was not true.
public class MyGallery extends Gallery {
public MyGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (changed) {
super.onLayout(changed, l, t, r, b);
}
}
}
Upvotes: 4
Reputation: 3335
I found the above Gallery extends solution to work fairly well. However it was still causing some jitter. By simply overriding the onLayout method and look for number of views on screen I ended up with a "smooth as silk" Gallery view. Note that I use this for a full screen slideshow effect.
public class SmoothGallery extends Gallery {
public SmoothGallery(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int viewsOnScreen = getLastVisiblePosition() - getFirstVisiblePosition();
if(viewsOnScreen <= 0)
super.onLayout(changed, l, t, r, b);
}
}
Upvotes: 3
Reputation: 5397
I had similar problem. Looks like it can be caused by changes in layout, e.g. if you change text in textview which has wrap_content width. This cases layout change and probably forces gallery to update itself and it snaps right on current item.
I was able to fix it by playing with layout, setting fixed sizes where I could etc. but I don't know about permanent and reliable solution
EDIT: also I found this hack if above doesn't work for you
http://www.unwesen.de/2011/04/17/android-jittery-scrolling-gallery/
Upvotes: 4