如何在android中创建如图片中的布局?

时间:2014-04-14 07:03:01

标签: android canvas progress-bar graphic

  

I want to create a layout as displayed in picture .

我关注了很多博客,但没有得到正确答案。主要问题是创建循环进度,在一些图形的帮助下显示。然而,无法走向成功。

Path p = new Path();
    p.moveTo(70, 10);
    p.lineTo(25, 100);
    p.lineTo(100, 50);
    p.lineTo(0, 50);
    p.lineTo(75, 100);
    p.lineTo(50, 0);
    // chk

    // //complete code
     ShapeDrawable progress1 = new ShapeDrawable(new ArcShape(180, -45));
     progress1.setIntrinsicHeight(50);
     progress1.setIntrinsicWidth(50);
     progress1.getPaint().setColor(Color.BLUE);
     progress1.getPaint().setStyle(Style.STROKE);
     progress1.getPaint().setStrokeWidth(5);

     ShapeDrawable progress2 = new ShapeDrawable(new ArcShape(0, 180));
     progress2.setIntrinsicHeight(50);
     progress2.setIntrinsicWidth(50);
     progress2.getPaint().setARGB(50, 200, 54, 54);
     progress2.getPaint().setStyle(Style.STROKE);
     progress2.getPaint().setStrokeWidth(5);
     iView.setImageDrawable(progress2);
     iView1.setImageDrawable(progress1);

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您不知道自己坚持使用哪个部分,那么您可能会做一个自定义视图,在其中使用onDraw方法定义绘图代码。

您可以使用相应目标颜色的粗笔划绘制弧形线。要使弧的末端变圆,请配置Paint对象的属性以满足您的需要,iirc使用的正确方法是Paint#setStrokeCap