【问题标题】:Customized Progressbar as indicator in Android自定义进度条作为 Android 中的指示器
【发布时间】:2015-05-07 13:29:19
【问题描述】:

有什么方法可以制作ProgressBarlike this

或者可以通过自定义RatingBar作为指标来实现吗?

如果是这样,我将如何在圆圈之间附加线条?

【问题讨论】:

  • 最好只制作自定义视图来制作那个东西。例如,您可以使用 imageview 来显示该线和带有该圆圈的 4 个视图,这并不困难且快速完成
  • @BrainAmplifier18 你可以使用图片来实现它。

标签: android android-progressbar


【解决方案1】:

您可以通过使用代表流程不同阶段的不同图像来实现这一点

保持可见性消失的图像视图,并在您想要显示时使其可见

在您的可绘制文件夹中保留一个类似于以下 progressanimation.xml 的 xml

    <?xml version="1.0" encoding="utf-8"?>

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
        android:oneshot="false">
        <item android:drawable="@drawable/progressone" android:duration  ="400" />
        <item android:drawable="@drawable/progresstwo" android:duration="400" />
        <item android:drawable="@drawable/progressthree" android:duration="400" />
        <item android:drawable="@drawable/progressfour" android:duration="400" />

    </animation-list>

    and use this as background of your ImageView like follows

                iv.setVisibility(View.VISIBLE);
                iv.setBackgroundResource(R.drawable.progressanimation);
                final AnimationDrawable mailAnimation = (AnimationDrawable) iv
                        .getBackground();
                iv.post(new Runnable() {
                    public void run() {
                        if (mailAnimation != null)
                            mailAnimation.start();
                        System.out.println("anim wrkingggg");
                    }
                });

这里iv是你的imageview。这段代码会自动改变背景。你可以让runnable在你自己的时间限制下运行。

【讨论】:

  • 您能否补充一下如何通过布局实现这一点?还有我在哪里可以在进度图像之间添加线条?
  • 我告诉过您为此保存不同的图像,例如一张图像应该是第 1 步到第 2 步,带有蓝线,并保留有灰线或淡化线。第 2 幅图像应该是第 1 到第 3 步,使用蓝线和剩余的淡化线,如这个你可以保留你想要显示的图像。如果你发布 xml 代码并告诉我你希望在哪里显示相同的内容,那么显示这个的 ImageView 可以作为相对布局的 centerInparent 或线性布局的 garvity 中心放置为你编辑它
  • 感谢您的努力,但我最终在图像视图之间使用了进度条。我使用了您的逻辑,即在步骤完成后以编程方式使其可见,并使用 setProgress(100), setMax(100) 方法进行进度。
  • 这个 SO 问题的后续问题,我还需要发布我的答案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多