@Override protected void onSizeChanged(int w,int h,int oldw,int oldh){
  super.onSizeChanged(w,h,oldw,oldh);
  setupBounds(w,h);
  setupPaints();
  invalidate();
}

@ Override protected void onSizeChanged ( int w , int h , int oldw , int oldh ) { super . onSizeChanged ( w , h , oldw , oldh ) ; setupBounds ( w , h ) ; setupPaints ( ) ; invalidate ( ) ; }
use onsizechanged instead of onattachedtowindow to get the dimensions of the view , because this method is called after measuring the dimensions of match_parent & wrap_content . use this dimensions to setup the bounds and paints .
