【问题标题】:I want make image slider like Marquee image? [closed]我想制作像 Marquee 图像这样的图像滑块? [关闭]
【发布时间】:2017-03-04 17:19:23
【问题描述】:

http://www.talk4u.in/TagoreAcadmy/marque.html

这是我的 html 格式的 url 现在我想要像这样的 bulid 图像滑块,但我不想使用 webview。我想使用 android 视图进行开发 并且图像移动应该像地球一样从重新开始到结束。

我有来自 mysql 数据库的多图像 url fatch,而不是像 marquee 那样显示在滑块上。

谢谢你

【问题讨论】:

    标签: android imageview marquee


    【解决方案1】:

    对“两个图像”使用 ValueAnimator 和 setTranslationX。

    看到这个:Android move background continuously with animation

    此外,在您的情况下,您需要更改滚动方向。 请注意下面的“已修改”。

    final ImageView backgroundOne = (ImageView) findViewById(R.id.background_one);
    final ImageView backgroundTwo = (ImageView) findViewById(R.id.background_two);    
    final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f); // Modified
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setInterpolator(new LinearInterpolator());
    animator.setDuration(10000L);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float progress = (float) animation.getAnimatedValue();
            final float width = backgroundOne.getWidth();
            final float translationX = width * progress;
            backgroundOne.setTranslationX(translationX);
            backgroundTwo.setTranslationX(translationX - width);
        }
    });
    animator.start();
    

    编辑1:

    如果你想使用来自服务器的图像,我建议你使用毕加索图像库。 http://square.github.io/picasso/

    1. 将毕加索依赖添加到 Build.gradle 文件中。 (

      • 将以下内容添加到依赖项中
        编译'com.squareup.picasso:picasso:2.5.2'
      • 然后按下 Android Studio 顶部的同步按钮
    2. 用毕加索加载图像。

      final ImageView backgroundOne = (ImageView) findViewById(R.id.background_one);
      final ImageView backgroundTwo = (ImageView) findViewById(R.id.background_two);
      
      Picasso.with(this).load("http://www.talk4u.in/wp-content/uploads/2017/02/cropped-logo2.png").into(backgroundOne);
      
      Picasso.with(this).load("http://www.talk4u.in/wp-content/uploads/2017/02/cropped-logo2.png").into(backgroundTwo);
      
      final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f); // Modified
      animator.setRepeatCount(ValueAnimator.INFINITE);
      animator.setInterpolator(new LinearInterpolator());
      animator.setDuration(10000L);
      animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
              final float progress = (float) animation.getAnimatedValue();
              final float width = backgroundOne.getWidth();
              final float translationX = width * progress;
              backgroundOne.setTranslationX(translationX);
              backgroundTwo.setTranslationX(translationX - width);
          }
      });
      
      animator.start();
      
      • 添加网络权限以访问互联网。

    【讨论】:

    • 哦,谢谢 cricket_007。我无法修复该代码块。
    猜你喜欢
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 2017-03-19
    相关资源
    最近更新 更多