1.新建自定義view horizontalprogressbarwithprogress,
2.自定義屬性
values目錄下新建attrs.xml檔案,定義各種屬性,並且給進度條引用
3.定義一些預設值和單位轉換方法
private static final int default_text_size = 10;//sp
private static final int default_text_color = 0xfffc00d1;
private static final int default_color_unreach = 0xffd3d6da;
private static final int default_height_unreach= 2;//dp
private static final int default_color_reach = default_text_color;
private static final int default_height_reach = 2;//dp
private static final int default_text_offset = 10;//dp
protected int mtextsize = sp2px(default_text_size);
protected int mtextcolor = default_text_color;
protected int munreachcolor = default_color_unreach;
protected int munreachheight = dp2px(default_height_unreach);
protected int mreachcolor = default_color_reach;
protected int mreachheight = dp2px(default_height_reach);
protected int mtextoffset = dp2px(default_text_offset);
protected paint mpaint = new paint();
private int mrealwidth;
protected int dp2px(int dpval)
protected int sp2px(int spval)
4.在構造方法裡取出自定義的屬性
public horizontalprogressbarwithprogress(context context,
attributeset attrs, int defstyle)
private void obtainstyledattrs(attributeset attrs)
typedarray 用完要記得recycle;
5.重寫onmesure()方法
Android之自定義進度條
進度條預設是不確定 indeterminate true android進度條 android進度條有4種風格可以使用。預設值是progressbarstyle。設定成progressbarstylesmall後,圖示變小。設定成progressbarstylelarge後,圖示變大 設定成prog...
Android自定義環形進度條
主頁面 author 有點涼了 public class mainactivity extends activity catch interruptedexception e start override public boolean oncreateoptionsmenu menu menu ov...
android 自定義 環形進度條
其實這個控制項很簡單,繼承view,在ondraw 中 繪製乙個圓和乙個圓弧即可,如下,對外暴露了乙個設定進度的方法,難點主要是數學計算 public class circleview extends view private void initvalues private void init ov...