我正在尝试创建一个圆角的正方形线进度条,以围绕图像绘制进度.
到目前为止,我有以下XML定义了我的圆角正方形线:
<shape xmlns:androID="http://schemas.androID.com/apk/res/androID" > <stroke androID:wIDth="6dp" androID:color="@androID:color/holo_green_light" /> <padding androID:left="5dp" androID:right="5dp" androID:bottom="5dp" androID:top="5dp" /> <corners androID:radius="50dp" /></shape>
我知道此解决方案:https://github.com/mrwonderman/android-square-progressbar,但我对效果不感兴趣,因为效果不是我想要的.
我试图在圆角正方形线的顶部创建一个普通圆,并尝试将其与PorterDuff合并,但是到目前为止,我也无法创建进度条效果.画一个圆圈,画出进度.
我还尝试过创建圆角正方形程序,以防XML膨胀被视为纯图像并且在PorterDuff合并过程中考虑了所有像素.但结果相同.
解决方法:
试试这个简单的自定义类:
class V extends VIEw { Path path = new Path(); Paint paint = new Paint(Paint.ANTI_AliAS_FLAG); float length; float[] intervals = {0, 0}; public V(Context context) { super(context); paint.setcolor(color.GREEN); paint.setStyle(Paint.Style.stroke); paint.setstrokeWIDth(20); } @OverrIDe protected voID onSizeChanged(int w, int h, int olDW, int oldh) { path.reset(); RectF rect = new RectF(0, 0, w, h); float inset = paint.getstrokeWIDth(); rect.inset(inset, inset); path.addRoundRect(rect, 100, 100, Path.Direction.CW); length = new PathMeasure(path, false).getLength(); intervals[0] = intervals[1] = length; PathEffect effect = new DashPathEffect(intervals, length); paint.setPathEffect(effect); } public voID setProgress(int progress) { PathEffect effect = new DashPathEffect(intervals, length - length * progress / 100); paint.setPathEffect(effect); invalIDate(); } @OverrIDe protected voID onDraw(Canvas canvas) { canvas.drawPath(path, paint); }}
测试代码(放入Activity#onCreate内部):
linearLayout ll = new linearLayout(this); ll.setorIEntation(linearLayout.VERTICAL); Seekbar sb = new Seekbar(this); ll.addVIEw(sb); final V v = new V(this); ll.addVIEw(v); setContentVIEw(ll); Seekbar.OnSeekbarchangelistener sbcl = new Seekbar.OnSeekbarchangelistener() { @OverrIDe public voID onProgressChanged(Seekbar seekbar, int progress, boolean fromUser) { v.setProgress(progress); } @OverrIDe public voID onStartTrackingtouch(Seekbar seekbar) {} @OverrIDe public voID onStopTrackingtouch(Seekbar seekbar) {} }; sb.setonSeekbarchangelistener(sbcl);
总结 以上是内存溢出为你收集整理的Android-圆角正方形线进度栏全部内容,希望文章能够帮你解决Android-圆角正方形线进度栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)