android - How to inflate xml-layout into child View -


i'm trying inflate xml-layout custom view-class, placed linearlayout in actual software. after googling managed create custom class inflates layout using following class:

    public class litteringview extends relativelayout {      public litteringview(context context) {         super(context);         // todo auto-generated constructor stub         view.inflate(context, r.layout.littering_layout, this);      }       public litteringview(context context, attributeset attrs) {         super(context, attrs);         // todo auto-generated constructor stub     }       @override     protected void onlayout(boolean changed, int l, int t, int r, int b) {         // todo auto-generated method stub          for(int = 0 ; < getchildcount() ; i++){              getchildat(i).layout(l, t, r, b);          }     }       @override     protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         // todo auto-generated method stub         super.onmeasure(widthmeasurespec, heightmeasurespec);     }      } 

now inflates when add linearlayout:

layout.addview(new litteringview(getactivity())); 

problem takes whole screen while screen should divided equally between linearlayout's 3 children. other views created dynamically. how can prevent taking whole space?

i'm trying create 1 custom view/class , package functions inside add parent layout (in case linearlayout) while wanting utilize xml define layout of view.

you need use 'weight' views. simple example this:

layout.layoutparams params = new linearlayout.layoutparams(width, height, weight); 

you need optimize case. give views weight value equally(eg: 1 of them) , should share view.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -