class ll extends ViewGroup
{
int n=2,H,V,W;
ll(Context c){super(c);}
public
void set(int n, int h, int v)
{
this.n = n;
this.H = h;
this.V = v;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
W = maxWidth - getPaddingLeft() - getPaddingRight();
int x = 0;
int y = 0;
int row = 0;
for (int i = 0; i < getChildCount(); i++)
{
View v = getChildAt(i);
if (v.getVisibility() != View.GONE)
{
v.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int height = v.getMeasuredHeight();
x += 1;
y = row * height + height;
if (x > n)
{
x = 1;
row++;
y = row * height + height;
}
}
}
y += (row + 2) * V+getPaddingTop() + getPaddingBottom();
setMeasuredDimension(maxWidth, y);
}
@Override
protected void onLayout(boolean p1, int l, int t, int r, int b)
{
l = getPaddingLeft();
t = getPaddingTop();
int x = l;
int y = 0;
int row = 1;
for (int i = 0; i < getChildCount(); i++)
{
View v = getChildAt(i);
if (v.getVisibility() != View.GONE)
{
int width = (W - H) / n - H;
int height = v.getMeasuredHeight();
x += width + H;
y = row * (height + V)+t;
if (x > l + W)
{
x = l + H + width;
row++;
y = row * (height + V)+t;
}
v.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
v.layout(x - width, y - height, x, y);
}
}
}
}