Android Gallery在图像之间转换(Android Gallery Transition Between Images)

编程入门 行业动态 更新时间:2024-10-25 17:25:16
Android Gallery在图像之间转换(Android Gallery Transition Between Images)

我有一个画廊,显示一些扑克牌的图像。 每张卡相隔20dp。

当我从一个图像移动到下一个图像时,图库会略微滚动到下一个图像,然后将自身更正回到图像。

另一个几乎肯定是相关的问题是,图像并没有干净地滚过视线。 这些图像似乎试图捕捉到完整视图,或者完全从视图中弹出,导致手动滚动在我滚动时左右抖动图像。

知道可能导致这种情况的原因吗?

以下是它的屏幕录制: http : //www.youtube.com/watch?v = MV4_48AW5Q&feature = youtu

这是画廊的xml:

<Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="200dp" android:scrollbars="none" android:layout_below="@+id/button1" android:layout_marginTop="60dp" android:spacing="20dp" android:animationDuration="3000" />

I have a gallery that shows the images of some playing cards. Each card is separated by 20dp.

When I move from one image to the next, the gallery scrolls slightly beyond the next image, and subsequently corrects itself back to the image.

Another issue, almost certainly related, is that the images are not scrolling past out of view cleanly. The images appear to be trying to either snap into full view, or to snap out of view entirely, causing manual scrolling to jerk the images side to side as I scroll.

Any idea what may be causing this?

Here is a screen recording of it: http://www.youtube.com/watch?v=Mvj4_48AW5Q&feature=youtu.be

Here is the xml for the gallery:

<Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="200dp" android:scrollbars="none" android:layout_below="@+id/button1" android:layout_marginTop="60dp" android:spacing="20dp" android:animationDuration="3000" />

最满意答案

我认为这是由Gallery在幻灯片动画上设置的动画插值器引起的。 过冲插补器将导致该行为。

如果你想覆盖它,我不确定它会有多容易。 我做了一个快速搜索,但我找不到任何可以让你轻松覆盖Gallery的默认插值器的东西。 我唯一能找到的就是这篇帖子,有人似乎通过创建一个扩展Android Gallery类的新Gallery类来取得成功,以覆盖默认的插补器。

Had to extend gallery, I think the issue had something to do with a timer that I had on screen. The issue is discussed further here: http://www.unwesen.de/2011/04/17/android-jittery-scrolling-gallery/

import android.content.Context; import android.os.SystemClock; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.Gallery; public class CustomGallery extends Gallery { private long mLastScrollEvent; private float mFlingMultiplier; public CustomGallery(Context context) { super(context); } public CustomGallery(Context context, AttributeSet attrs) { super(context, attrs); } public CustomGallery(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { long now = SystemClock.uptimeMillis(); if (Math.abs(now - mLastScrollEvent) > 500 * mFlingMultiplier) { super.onLayout(changed, l, t, r, b); } } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { mLastScrollEvent = SystemClock.uptimeMillis(); mFlingMultiplier = 1; return super.onScroll(e1, e2, distanceX, distanceY); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { mFlingMultiplier = Math.abs(velocityX/100); return super.onFling(e1, e2, velocityX, velocityY); } }

更多推荐

本文发布于:2023-07-05 06:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Gallery   Android   Transition   Images

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!