public class GridLines extends java.lang.Object implements RhythmSpecLayer
Modifier and Type | Class and Description |
---|---|
static class |
GridLines.Factory
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_GRID_COLOR |
static int |
DEFAULT_THICKNESS
Default grid line thickness (1px)
|
protected int |
mEdgeAffinity |
protected int |
mLimit |
protected int |
mOffset |
protected android.graphics.Paint |
mPaint |
protected float |
mStep |
protected int |
mThickness |
Modifier | Constructor and Description |
---|---|
protected |
GridLines()
Create a spec layer that displays dimensions label.
|
|
GridLines(int edgeAffinity,
float step)
Create a layer that draws horizontal or vertical grid lines.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(android.graphics.Canvas canvas,
android.graphics.Rect drawableBounds)
Draw itself to the provided canvas within provided bounds according to internal configuration (if any)
|
GridLines |
setColor(int color)
Set grid line color
|
GridLines |
setEdgeAffinity(int edgeAffinity)
Set edge affinity of the grid
|
GridLines |
setLimit(int limit)
Set the maximum number of steps to outline, respecting layer’s gravity (i.e.
|
GridLines |
setOffset(int offset)
Set additional grid offset.
|
GridLines |
setStep(float step)
Set the step of grid lines
|
GridLines |
setThickness(int thickness)
Set grid line thickness
|
public static final int DEFAULT_GRID_COLOR
public static final int DEFAULT_THICKNESS
protected float mStep
protected int mThickness
protected int mLimit
protected int mOffset
protected int mEdgeAffinity
protected android.graphics.Paint mPaint
public GridLines(int edgeAffinity, float step)
edgeAffinity
- Controls grid alignment and orientation. Gravity.TOP
and Gravity.BOTTOM
mean horizontal lines, and Gravity.LEFT
and Gravity.RIGHT
mean vertical lines, and the difference between those is from what edge of the view the steps
are counted. A good example where this can be useful is having a left-aligned and a
right-aligned layer on the left and the right half of the view when its width is not an exact
multiple of the step.step
- Grid step, in pixels. Allows for float values to properly accommodate devices with non-round
dip-to-pixel ratio (1.5x on hdpi, 2.5x on Nexus 5X etc)protected GridLines()
Create a spec layer that displays dimensions label.
This is a minimum constructor for the factory — only paints and reusable objects are initialized. Developers extending this class are responsible for setting all fields to proper argument values.
public GridLines setStep(float step)
step
- Grid step, in pixels. Allows for float values to properly accommodate devices with non-round
dip-to-pixel ratio (1.5x on hdpi, 2.5x on Nexus 5X etc)public GridLines setEdgeAffinity(int edgeAffinity)
edgeAffinity
- Controls grid alignment and orientation. Use Gravity.TOP
or Gravity.BOTTOM
for horizontal lines counting from top or bottom, and Gravity.LEFT
or
Gravity.RIGHT
for vertical lines cointing from left or right edge of the screen
respectively.public GridLines setColor(int color)
color
- Grid line color, in #AARRGGBB format as usualpublic GridLines setThickness(int thickness)
thickness
- Grid line thickness, in pixelspublic GridLines setLimit(int limit)
Gravity.BOTTOM
and the limit is 4, this layer will draw four lines enclosing 4 cells. Default is no limit.limit
- Number of lines to draw. Setting zero or less means no limit.public GridLines setOffset(int offset)
offset
- Grid offset in pixels. Regardless of gravity, positive offset means right/down, negative means
left/uppublic void draw(android.graphics.Canvas canvas, android.graphics.Rect drawableBounds)
RhythmSpecLayer
draw
in interface RhythmSpecLayer
canvas
- Canvas for the layer to draw itself todrawableBounds
- Bounds where this layer should draw itself. Since these are the bounds of a RhythmDrawable
connected to the view, they are usually the same as the view’s bounds, so
you can use this parameter to get the view’s dimensions should you need them.