其實這個控制項很簡單,繼承view,在ondraw 中 繪製乙個圓和乙個圓弧即可,**如下,對外暴露了乙個設定進度的方法,難點主要是數學計算
public class circleview extends view
private void initvalues()
private void init()
@override
protected void ondraw(canvas canvas)
canvas.drawcircle(mrockbollposition.x, mrockbollposition.y, mradius , mpaint); }
@override
protected void onmeasure(int widthmeasurespec, int heightmeasurespec)
private int getscreenwidth()
@override
public boolean ontouchevent(motionevent event)
break;
case motionevent.action_move:
if(isdraging)
break;
case motionevent.action_up:
isdraging = false;
mradius = 8;
break;
default:
break;
} invalidate();
return true;
} private point getonradius(point cp)
private void flushradian(point cp, point pp) else
}elseelse
} progresslistener.setprogresschanged((float)playedradian/360f);
// system.out.println("atan:"+(atan/math.pi)*180);
} private int distance(point cp, point np) catch (exception e)
return 0; }
/*** @describe 觸控點與中心點之間直線與水平方向的夾角角
* @param a
* @param b
* @return
*/public static float getradian(point a, point b)
/*** 根據進度條角度重新整理小球的位置
* * @param playedradian2
*/private void flushrockposition(int ang)
public void setprogress(float progress)
private progresschangedlistener progresslistener;
public void setprogresslistener(progresschangedlistener progresslistener)
public inte***ce progresschangedlistener
}
效果圖如下
Android自定義環形進度條
主頁面 author 有點涼了 public class mainactivity extends activity catch interruptedexception e start override public boolean oncreateoptionsmenu menu menu ov...
android 簡單自定義環形進度條
一 通過動畫實現 定義res anim loading.xml如下 html view plain copy print?xml version 1.0 encoding utf 8 animation list android oneshot false xmlns android item an...
Android自定義進度條
1.新建自定義view horizontalprogressbarwithprogress,2.自定義屬性 values目錄下新建attrs.xml檔案,定義各種屬性,並且給進度條引用 3.定義一些預設值和單位轉換方法 private static final int default text si...