Skip to content

Instantly share code, notes, and snippets.

@SouravKumarPandit
Last active August 21, 2018 10:18
Show Gist options
  • Save SouravKumarPandit/1dee412d20210375f7e495bce8ebb9ab to your computer and use it in GitHub Desktop.
Save SouravKumarPandit/1dee412d20210375f7e495bce8ebb9ab to your computer and use it in GitHub Desktop.
public class LinearLayout2D extends LinearLayout {
Paint rectPaint;
int intShaderType=0;
public LinearLayout2D(Context context)
{
super(context);
init(context);
}
private void init(Context context)
{
rectPaint = new Paint();
// rectPaint.setDither(true);
rectPaint.setStyle(Paint.Style.FILL);
rectPaint.setStrokeJoin(Paint.Join.ROUND);
rectPaint.setStrokeCap(Paint.Cap.ROUND);
rectPaint.setAntiAlias(true);
// setGradient(0xfff9f9f9, 0xffc6c6c6);
}
public LinearLayout2D(Context context, @Nullable AttributeSet attrs)
{
super(context, attrs);
init(context);
}
public LinearLayout2D(Context context, @Nullable AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
init(context);
}
@Override
protected void dispatchDraw(Canvas canvas)
{
// setBackgroundColor(Color.GREEN);
// setGradient(Color.parseColor("#f5f5f5"), Color.parseColor("#e4e4e4"));
// setGradient(Color.parseColor("#ececec"),Color.parseColor("#fdfdfd"));
// setGradient(0xfff2edef,0xffd6cbcf);
setGradient(0xffffffff,0xffd6d6d6);
canvas.drawRect(0, 0, getWidth(), getHeight(), rectPaint);
super.dispatchDraw(canvas);
}
public void setGradient(int sColor, int eColor)
{
rectPaint.setShader(new LinearGradient(0, 0, 0, getHeight() / 2,
new int[]{sColor, eColor},
new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment