Android Canvas for 2 coloured background -


i want achieve below meter use of canvas .

enter image description here

as can see black portion has 2 colors in . able set color of black moving image using shape drawable. code , image have achieved far given below. how can have desired result. novice in canvas .

enter image description here

    float[] outerr = new float[] { 7, 7,curve , curve, curve, curve, 7, 7};     shapedrawable mmovingrectangle = new shapedrawable();     mmovingrectangle.setshape(new roundrectshape(outerr, null, null));     mmovingrectangle.getpaint().setcolor(getresources().getcolor(r.color.black_alfa_60)); 

look @ shapedrawable shaderfactory

private void fillcustomgradient(view v) {     final view view = v;     drawable[] layers = new drawable[1];      shapedrawable.shaderfactory sf = new shapedrawable.shaderfactory() {         @override         public shader resize(int width, int height) {             lineargradient lg = new lineargradient(                     0,                     0,                     0,                     view.getheight(),                     new int[] {                              getresources().getcolor(r.color.color1), // please input color resource color-1,2,3,4                              getresources().getcolor(r.color.color2),                              getresources().getcolor(r.color.color3),                              getresources().getcolor(r.color.color4)},                     new float[] { 0, 0.49f, 0.50f, 1 },                     shader.tilemode.clamp);             return lg;         }     };     paintdrawable p = new paintdrawable();     p.setshape(new rectshape());     p.setshaderfactory(sf);     p.setcornerradii(new float[] { 5, 5, 5, 5, 0, 0, 0, 0 });     layers[0] = (drawable) p;      layerdrawable composite = new layerdrawable(layers);     view.setbackgrounddrawable(composite); } 

may helpful you


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -