title: How to draw a line with custom stroke style in android?
body: <p><strong>Edit :</strong>
  my first part of question is unique, but the second part is similar to some other questions.
  <strong>Main Problem:</strong>
  this is my class code,I use this class to draw lines with custom stroke shape from drawable . I want to draw a line, but it just draw some dots as shown in the picture below. Is there any idea to fix this problem?
  <a href="https://i.stack.imgur.com/fuouk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fuouk.jpg" alt="result"></a></p>
  
  <pre><code>public class MainDrawingView extends View {
      private Bitmap mBitmapBrush;
      private Bitmap rBitmapBrush;
      private Vector2 mBitmapBrushDimensions;
      private List&lt;Vector2&gt; mPositions = new ArrayList&lt;Vector2&gt;(100);
  
      private static final class Vector2 {
          public Vector2(float x, float y) {
              this.x = x;
              this.y = y;
          }
          public final float x;
          public final float y;
      }
  
      public MainDrawingView(Context context, @Nullable AttributeSet attrs) {
          super(context, attrs);
          mBitmapBrush = BitmapFactory.decodeResource(context.getResources(), R.drawable.brush01);
          rBitmapBrush = Bitmap.createScaledBitmap(mBitmapBrush, 10, 10, false);
          mBitmapBrushDimensions = new Vector2(rBitmapBrush.getWidth(), rBitmapBrush.getHeight());
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          for (Vector2 pos : mPositions) {
              canvas.drawBitmap(rBitmapBrush, pos.x, pos.y, null);
          }
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
  
          int action = event.getAction();
          switch (action) {
              case MotionEvent.ACTION_MOVE:
                  final float posX = event.getX();
                  final float posY = event.getY();
                  mPositions.add(new Vector2(posX - mBitmapBrushDimensions.x / 2, posY - mBitmapBrushDimensions.y / 2));
                  invalidate();
          }
          return true;
      }
  }
  </code></pre>
  
  <p><strong>Update:</strong>
  I try another class to draw a line with my drawable, but I faced 2 new problem! the first; when I use <strong>setShader</strong> , there is no any line when touch and move my finger on the screen. and the second;when comment the <strong>setShader</strong> line in the code, I could draw a simple black line, but if I draw a curved line rapidly, the result is a broken line ! and not a true curve line.so what is your idea to solve these problems?</p>
  
  <p><a href="https://i.stack.imgur.com/ldcTX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ldcTX.jpg" alt="result2"></a></p>
  
  <pre><code>public class MainDrawingView extends View {
      private Bitmap mBitmapBrush;
      private Bitmap rBitmapBrush;
      private BitmapShader mBitmapShader;
      private Paint paint = new Paint();
      private Path path = new Path();
  
      public MainDrawingView(Context context, @Nullable AttributeSet attrs) {
          super(context, attrs);
          mBitmapBrush = BitmapFactory.decodeResource(context.getResources(), R.drawable.brush01);
          rBitmapBrush = Bitmap.createScaledBitmap(mBitmapBrush, 10, 10, false);
          mBitmapShader = new BitmapShader(rBitmapBrush, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
          paint.setAntiAlias(true);
          paint.setStrokeWidth(5f);
          paint.setColor(Color.BLACK);
          paint.setStyle(Paint.Style.STROKE);
          paint.setStrokeJoin(Paint.Join.ROUND);
          //paint.setShader(mBitmapShader);
  
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          canvas.drawPath(path, paint);
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
  
          float eventX = event.getX();
          float eventY = event.getY();
  
          switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                  path.moveTo(eventX, eventY);
                  return true;
              case MotionEvent.ACTION_MOVE:
                  path.lineTo(eventX, eventY);
                  break;
              default:
                  return false;
          }
          invalidate();
          return true;
      }
  }
  </code></pre>