Last active
December 19, 2015 00:29
-
-
Save julianshen/5869423 to your computer and use it in GitHub Desktop.
Generate layout parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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