Android Canvas for 2 coloured background -
i want achieve below meter use of canvas .
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 .
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
Post a Comment