Skip to content

Instantly share code, notes, and snippets.

@mrabelwahed
Last active January 25, 2018 17:03
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 mrabelwahed/f36e45ad81aa2886b184535b6b69080c to your computer and use it in GitHub Desktop.
Save mrabelwahed/f36e45ad81aa2886b184535b6b69080c to your computer and use it in GitHub Desktop.
package com.ramadan_apps.mylibrary;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by Mahmoud Ramadan on 1/25/18.
*/
public class CircleView extends View {
private float dim;
private String shape;
public CircleView(Context context) {
super(context);
}
public CircleView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context,attrs);
}
private void init(Context context , AttributeSet attrs){
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs,R.styleable.CircleView,0,0);
try {
dim = typedArray.getDimension(R.styleable.CircleView_dim,20f);
shape = typedArray.getString(R.styleable.CircleView_shape);
}finally {
typedArray.recycle();
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(dim,dim,dim,new Paint());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment