Gallery scrolling image jumps after moving 3/4 th of the screen
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开发者_JAVA技巧 smooth? Any sample code would be of great help.
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/
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);
}
}
}
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);
}
}
精彩评论