in application have layout this:
1) main view can moved , dragged.
2) controllers can added inside main view. , position can set topleft
or else. topleft
here means relative main view.(see this image)
now tried implement extending viewgroup
, , main view
, controllers
extends view
.
this have done now:
class myviewcontainer extends viewgroups{ @override public void onlayout(boolean changed,int l,int t,int b, int r){ for(int i=0,len=getchildcounts,i<len;i++){ view v=getchildat(i); if(v instanceof mainview){ v.layout(l,t,b,r); } else if(v instanceof mycontroller){ //here not know how layout childs according position } } } } abstract mycontroller extends view{ } class zoomcontroller extends mycontroller{ @override public void ondraw(canvas c){ } } class anothercontroller extends mycontroller{ @override public void ondraw(canvas c){ } } class mainview extends view{ @override public void ondraw(canvas c){ } }
as can see, have no idea layout mycontrollers
. since not know width , height of controller
. beacuse size of controllers depended on how being drawn.
how make it?
try this. work, master view has come before controllers.
class myviewcontainer extends viewgroups{ @override public void onlayout(boolean changed,int l,int t,int b, int r){ view masterview = null; for(int i=0,len=getchildcounts,i<len;i++){ view v=getchildat(i); if(v instanceof mainview){ masterview = v; v.layout(l,t,b,r); } else if(v instanceof mycontroller){ // layout views here. relativelayout.layoutparams params = new relativelayout.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); if (masterview != null && topleft) { params.addrule(relativelayout.align_left, masterview.getid()); params.addrule(relativelayout.align_top, masterview.getid()); } if (masterview != null && bottomright) { params.addrule(relativelayout.align_right, masterview.getid()); params.addrule(relativelayout.align_bottom, masterview.getid()); } v.setlayoutparams(params); } } } }
Comments
Post a Comment