【问题标题】:Smooth slide image one way一种平滑的幻灯片图像
【发布时间】:2016-01-13 23:47:42
【问题描述】:

我有对称的图像,我想从右到左平滑地无限移动它。我尝试使用 TranslateAnimation,但首先我必须正确设置我的图像,这非常困难,主要是因为该图像使用了所有屏幕宽度,我应该设置负边距。还有其他解决方案吗?是否有可能在不移动 ImageView 的情况下移动图像?

【问题讨论】:

  • 您也可以为此使用寻呼机。这是演示codetheory.in/…
  • 是的,“正确”的方法是使用 ViewPager 滑动图像。

标签: android android-imageview android-transitions


【解决方案1】:

最后我自己做了,解决办法是把2个图像放在一起,然后测量屏幕宽度并使用2个TranslateAnimation,一个从屏幕宽度到0,第二个从0到-屏幕宽度:

    TranslateAnimation anim = new TranslateAnimation(0, -screenWidth, 0, 0);
    TranslateAnimation anim2 = new TranslateAnimation(screenWidth, 0, 0, 0);
    anim.setDuration(5000);
    anim.setRepeatCount(Animation.INFINITE);
    anim.setInterpolator(new LinearInterpolator());
    anim2.setDuration(5000);
    anim2.setRepeatCount(Animation.INFINITE);
    anim2.setInterpolator(new LinearInterpolator());
    backgroundOverlayImage.startAnimation(anim);
    backgroundOverlayImage2.startAnimation(anim2);

【讨论】:

    【解决方案2】:

    我认为这就是你想要做的:

            TranslateAnimation anim = new TranslateAnimation(0, -1000, 0, 0);
            anim.setDuration(1500);
            anim.setFillAfter(true);
            anim.setRepeatCount(0);
            anim.setInterpolator(this, Android.Resource.Animation.LinearInterpolator);
    

    编辑: 最后别忘了imageView.startAnimation(anim);

    【讨论】:

    • 这个解决方案的问题很少,当图像移动太多时会显示空白,我必须设置负边距才能使其正常工作。
    【解决方案3】:

    虽然您得到了答案,try 这个存储库,这将解决您对幻灯片的所有疑问,还将为您的视图添加自定义动画!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2016-09-26
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多