title: How to programmatically create gradient color background for a View?
body: <p><strong>strong text</strong>There is an interface component View (simple rectangle) let's call it "my_view". 
  ...</p>
  
  <pre><code>View myView = (View) findViewById(R.id.my_view);
  </code></pre>
  
  <p>...
  I want to programmatically create linear gradient color background for a myView.
  The two colors of the gradient are set by variables that will change frequently. So I need to find an optimized way.
  I tried to do this:</p>
  
  <pre><code>myView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
      {
          @Override
          public boolean onPreDraw()
          {
              myView.getViewTreeObserver().removeOnPreDrawListener(this);
              int view_height = myView.getHeight();
              ShapeDrawable myDrawable = new ShapeDrawable(new RectShape());
              myDrawable.getPaint().setShader(new LinearGradient(0, 0, 0, view_height, color1, color2, Shader.TileMode.CLAMP));
              myView.setBackgroundDrawable(myDrawable);
              return false;
          }
      });
  </code></pre>
  
  <p>Everything is working. This code should be executed each time when the progress of the Seekbar changes. After testing, I realized that this is a very bad method.Everything works as it should, but lags are noticeable.</p>
  
  <hr>
  
  <p><strong>Upd:</strong>
  The problem was solved! The best method is to create a Custom Drawable! Thanks to all forum members who gave me tips, especially <strong>pskink</strong>, who gave the best advice.</p>