Hi there,

I'm am trying to learn how to create LayoutGroups. For a start, I
created MyLinearLayout which is supposed to force all children into
same width (yes, there is layout_weight, but that's beside the
point :-)

However, the children won't show up. What am I missing here?

public class MyLinearLayout extends LinearLayout {

        public MyLinearLayout(Context context) {
                super(context);
        }

        public MyLinearLayout(Context context, AttributeSet attrs) {
                super(context, attrs);
        }

        private final static int PADDING = 2;

        @Override
        protected void onLayout( boolean changed, int l, int t, int r, int
b ) {
                //super.onLayout( changed, l, t, r, b );
                //if( !changed ) return;
                int len = getChildCount();
                int w = ((r-l)-(len-1)*PADDING)/len;
                int pos = l;
                for( int i=0; i<len; i++ ) {
                        View c = getChildAt(i);
                        c.layout( pos, t, pos+w, b );
                        pos += w + PADDING;
                }
        }

        @Override
        protected void onMeasure( int wSpec, int hSpec ) {
                int ws = MeasureSpec.getMode( wSpec );
                int w = MeasureSpec.getSize(wSpec);
                int hs = MeasureSpec.getMode( hSpec );
                int h = MeasureSpec.getSize(hSpec);
                setMeasuredDimension(wSpec,hSpec);
                int len = getChildCount();
                int w1 = (w-(len-1)*PADDING)/len;
                for( int i=0; i<len; i++ ) {
                        View c = getChildAt(i);
                        c.measure(
                                MeasureSpec.makeMeasureSpec(w1,ws),
                                MeasureSpec.makeMeasureSpec(h, hs)
                        );
                }
                //super.onMeasure( wSpec, hSpec );
        }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to