android进度条中的垂直线 [英] Vertical line in android progress bar

查看:310
本文介绍了android进度条中的垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个水平进度条,在主过程结束时带有黑色垂直线。对于我的代码,进度条还可以,但是该行始终在中间。我尝试使用 clip ,但是它消失了,而不是出现在段的结尾。

I need a horizontal progress bar with a black vertical line at the end of the main process. With my code, the progress bar is ok but the line is always in the middle of the bar. I tried using clip but then it disappears instead of going at the end of the segment.

我的代码

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@android:id/background">
     <shape android:shape="rectangle">
         <corners android:radius="5dip" />
         <solid android:color="#ffffffff" />
         <stroke android:width="1dip" android:color="#ff000000" />
     </shape>
 </item>

 <item android:id="@android:id/progress">
     <clip>
         <shape>
             <corners android:radius="5dip" />
             <solid android:color="#33b5e5" />
             <stroke android:width="1dip" android:color="#ff000000" />
         </shape>
     </clip>
 </item>

 <item android:id="@+id/line">
     <rotate android:fromDegrees="90"
            android:toDegrees="90" >
         <shape android:shape="line">
             <stroke android:width="5dp" android:color="#ff000000"/> 
         </shape>
     </rotate> 
 </item>

</layer-list>

我的问题

由于必须在栏中添加其他过程,因此无法在该行中使用 secondaryProgress 标记。另外,线条的位置和条形的颜色还有很多可能性,我不想做10种不同的可绘制对象。

As I have to add another process to the bar, I can't use the secondaryProgress tag for the line. Also, there are quite a lot of possibilities for the position of the line and for the colors of the bar, and I wouldn't like to do 10 different drawables.

是否可以通过进度栏实现我想要的目标,或者有更好的方法吗?我搜索有关垂直线,多色条甚至堆积图的线程。但是以某种方式,我找不到合适的库或简单的方法来处理进度条。

Is it possible to achieve what I want with a progress bar or is there a better way to do it? I searched for threads about vertical line and also about multicolor bars, and even about stacked charts. But somehow, I wasn't able to find an appropriate library or a simple way to do my progress bar.

目标

下面是我想要的内容的图片:

Here is a picture of what I want to have at the end:

我需要竖线才能在条形图中显示100%的标记, 超过100%。进度可以从左到右或从右到左显示。

I need the vertical line for displaying a 100% mark in bars which may "exceed 100%". The progress may be displayed from left to right or from right to left.

推荐答案

我找到了解决方案...我删除了上面代码中的订单项,并将以下代码添加到 onDraw()方法中:

I found a solution... I removed the line item from the code above and added the following code to the onDraw() method:

Paint linePaint = new Paint();
linePaint.setColor(getResources().getColor(android.R.color.black));
final float lineWidth = 5f;
linePaint.setStrokeWidth(lineWidth);
canvas.drawLine(getWidth() * m100 / 100, 0, 
                getWidth() * m100 / 100, getHeight(), 
                linePaint);

在代码中, m100 是位置行的整数。例如,如果100%的喜欢标记应位于钢筋长度的80%处,则为80。

In the code, m100 is the position of the line as integer. For example, it is 80 if the 100% like mark should be positioned at 80% of the bar length.

这篇关于android进度条中的垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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