Хм, не знаю как подцепить файл сюда. Но может быть вот такой компонент подойдет?
public class DashboardLayout extends ViewGroup {
private final static String TAG = DashboardLayout.class.getName();
private final static int DEFAULT_COLUMNS = 3;
private int columns;
public DashboardLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DashboardLayout);
try {
setColumns(a.getInt(R.styleable.DashboardLayout_dashboardColumns, DEFAULT_COLUMNS));
} finally {
a.recycle();
}
}
public DashboardLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DashboardLayout(Context context) {
this(context, null);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int totalChildWidth = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
int visibleCount = getVisibleCount();
if (visibleCount > 0) {
int childWidth = totalChildWidth / columns;
int childHeight = childWidth;
int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
int childHeightSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY);
for (int i = 0, N = getChildCount(); i < N; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.measure(childWidthSpec, childHeightSpec);
}
}
}
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childLeft = l + getPaddingLeft();
int childTop = t + getPaddingTop();
for (int i = 0, N = getChildCount(); i < N; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
childTop + child.getMeasuredHeight());
childLeft += child.getMeasuredWidth();
if (childLeft + getPaddingRight() >= r) {
childLeft = l + getPaddingLeft();
childTop += child.getMeasuredHeight();
}
}
}
}
/***
* Set number of columns. By default DashboardLayout uses 3 columns
*
* @param value
* - number of columns
*/
public void setColumns(int value) {
if (value != columns) {
columns = value;
requestLayout();
}
}
/***
* Returns number of columns.
*
* @return number of columns
*/
public int getColumns() {
return columns;
}
private int getVisibleCount() {
int count = 0;
for (int i = 0, N = getChildCount(); i < N; i++) {
if (getChildAt(i).getVisibility() != GONE) count++;
}
return count;
}
}
Еще надо положить в res/values/attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="DashboardLayout">
<attr name="dashboardColumns" format="integer" />
</declare-styleable>
</resources>