如何在"android Horizo​​ntal Progress bar"中绘制垂直线 [英] How to draw a vertical line in "android Horizontal Progress bar"

查看:129
本文介绍了如何在"android Horizo​​ntal Progress bar"中绘制垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个自定义的水平进度条,如下图所示.

I need to make a custom horizontal progress bar like the image given below.

我使用下面的layer-list设计了进度条,如下图所示可绘制的:

And I have designed the the progress bar like the image below using layer-list in drawable:

我想在进度大于25时画一条垂直线,如图所示我需要的.我写了这段代码,但是没用.

I want to draw a vertical line when progress is greater than 25 like the image that I need. I wrote this code but it didn't work.

myProgressBar = (ProgressBar) findViewById(R.id.progress);
Canvas canvas = new Canvas();
Paint p = new Paint();
p.setStrokeWidth(2);
p.setColor(Color.WHITE);
canvas.drawLine(a, b, c, d, p);

if(myProgressBar.getProgress() > 25){
    myProgressBar.draw(canvas);
}

因此,请帮助我在进度栏中画一条垂直线.这是我的第一次问题在堆栈溢出中,因此可能对此有些错误感到抱歉.

So please help me in drawing a vertical line in the progress bar. This is my first question in the stack overflow so there may be some mistakes sorry for this.

推荐答案

您可以尝试使用图层列表

You can try to using layer list

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:id="@android:id/background">
       <shape>
            <corners android:radius="3dip" />
            <gradient
                android:angle="0"
                android:endColor="#e9e9f4"
                android:startColor="#e9e9f4" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:angle="0"
                    android:endColor="#16a023"
                    android:startColor="#16a023" />
            </shape>
        </clip>
    </item>
    <item android:id="@+id/line" >
        <rotate android:fromDegrees="90" android:pivotX="10%" >
           <shape android:shape="line" >
               <stroke android:width="2dp" android:color="#ffffff" />
           </shape>
       </rotate>
   </item>
</layer-list>

这篇关于如何在"android Horizo​​ntal Progress bar"中绘制垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆