What about the following layout ?
1st Attempt was to create custom RelativeLayout
with OnDraw
overriding as follows
SliceLayout Class :
public class SliceLayout extends LinearLayout {
public SliceLayout(Context Context, Slice Slice) {
super(Context);
mPaint = new Paint();
mPaint.setStyle(Style.FILL);
mPaint.setColor(Color.RED);
mPath = Draw(Slice.A, Slice.B, Slice.C);
}
final static String TAG = "Slice";
Paint mPaint;
Path mPath;
private Path Draw(Point A, Point B, Point C) {
Log.e(TAG, "Draw");
Path Pencil = new Path();
Pencil.moveTo(A.x, A.y);
Pencil.lineTo(B.x, B.y);
Pencil.lineTo(C.x, C.y);
return Pencil;
}
@Override
protected void onDraw(Canvas canvas) {
Log.e(TAG, "Drawing");
canvas.drawPath(mPath, mPaint);
}
}
Slice Class :
public class Slice {
public enum Location {
N, S, W, NE, NW, SE, SW, EN, ES
}
public Point A;
public Point B;
public Point C;
private void Define(Point A, Point B, Point C) {
this.A = A;
this.B = B;
this.C = C;
}
public Slice(Point Display, Location Location) { //Display = Size of display
switch (Location) {
case N:
Define(new Point(0, 0), new Point(Display.x, 0), new Point(0,
Display.y));
case S:
Define(new Point(Display.x, 0), new Point(Display.x, Display.y),
new Point(0, Display.y));
default:
Define(new Point(0, 0), new Point(0, 0), new Point(0, 0));
}
}
}
It's working but I don't need to go the heavy code low performance way also I failed to initialize components because of inheritance in XML !
2nd Attempt was to try creating same layout but XML
version
Question :
I feel loose, Can you Help me choose the right way or Suggest another proven
way !