Skip to content

Instantly share code, notes, and snippets.

@julianshen
Last active December 19, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianshen/5869423 to your computer and use it in GitHub Desktop.
Save julianshen/5869423 to your computer and use it in GitHub Desktop.
Generate layout parameters
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new CellLayoutParams(getContext(), attrs);
}
public static class CellLayoutParams extends MarginLayoutParams {
public int cellX = 0;
public int cellY = 0;
public int cellRowSpan = 1;
public int cellColSpan = 1;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
public CellLayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.SimpleCellLayout);
for (int i = 0; i < a.getIndexCount(); i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.SimpleCellLayout_colspan:
cellColSpan = a.getInt(attr, cellColSpan);
if (cellColSpan < 1) {
cellColSpan = 1;
}
break;
case R.styleable.SimpleCellLayout_rowspan:
cellRowSpan = a.getInt(attr, cellRowSpan);
if (cellRowSpan < 1) {
cellRowSpan = 1;
}
break;
case R.styleable.SimpleCellLayout_cellX:
cellX = a.getInt(attr, cellX);
if (cellX < 0) {
cellX = 0;
}
break;
case R.styleable.SimpleCellLayout_cellY:
cellY = a.getInt(attr, cellY);
if (cellY < 0) {
cellY = 0;
}
break;
}
}
a.recycle();
}
public CellLayoutParams(int width, int height) {
super(width, height);
}
public CellLayoutParams(MarginLayoutParams source) {
super(source);
}
public CellLayoutParams(LayoutParams source) {
super(source);
}
public void saveMeasureResult(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment