我正在做一个与画廊显示几个图像的应用程序,当我滚动图像时,它们在某个点后移动和跳跃。我如何让它们变得平滑?任何示例代码都会有很大帮助。
发布于 2011-08-18 05:52:33
我也遇到过类似的问题。看起来这可能是由布局中的更改引起的,例如,如果您在具有wrap_content宽度的textview中更改文本。这种情况下布局改变,并可能强制画廊更新自己,它捕捉到当前的项目。
我可以通过调整布局,设置固定大小等方式来修复它,但我不知道是否有永久可靠的解决方案
编辑:我也发现了这个技巧,如果上面的方法对你不起作用的话
http://www.unwesen.de/2011/04/17/android-jittery-scrolling-gallery/
发布于 2012-02-10 09:50:44
我设法解决了这个问题,方法是覆盖Gallery父元素中的onLayout()方法,然后忽略任何changed标志不为真的调用。
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);
}
}
}发布于 2012-02-22 21:45:13
我发现上面的Gallery extends解决方案工作得相当好。然而,它仍然引起了一些抖动。通过简单地覆盖onLayout方法并查看屏幕上的视图数量,我最终得到了一个“像丝绸一样平滑”的画廊视图。请注意,我使用它来实现全屏幻灯片效果。
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);
}
}https://stackoverflow.com/questions/7094655
复制相似问题