2

I am able to draw the horizontal dashed line with the code provided by this question.

This as a background for a view whose width is 1dp and height is fill-parent.but,if i try to draw the vertical line changing the width and height of the view then the dashed vertical line is not appearing.

Community
  • 1
  • 1
user1108995
  • 175
  • 1
  • 4
  • 11

3 Answers3

4

Edit... Better still, create a path and draw that path.

Paint paintDots = new Paint();
paintDots.setStyle(Paint.Style.STROKE);
PathEffect pe = new DashPathEffect(new float[] {5, 20}, 0);
paintDots.setPathEffect(pe);
paintDots.setStrokeWidth(5);

Path p = new Path();
p.moveTo(100, 0);
p.lineTo(100, 200);
canvas.drawPath(p, paintDots);

Surely there's a better way than this, but I just made a rectangle with 0 width. There are limitations with this approach. I would recommend making the gap in the path effect large in case the sides of the "rectangle" clash.

Paint paintDots = new Paint();
paintDots.setStyle(Paint.Style.STROKE);
PathEffect pe = new DashPathEffect(new float[] {5, 20}, 0);
paintDots.setPathEffect(pe);
paintDots.setStrokeWidth(5);            

canvas.drawRect(new Rect(100,0,100,200), paintDots);
Dittimon
  • 986
  • 2
  • 14
  • 28
0

I've had a similar situation where I wanted such an element. The (not so good) solution is to set up a height in dp like 40dp for an element in a normal ListAdapter etc.

fill_parent seems to get ignored.

Best wishes, Tim

Tim
  • 6,692
  • 2
  • 25
  • 30
0

create a linearlayout with horizontal orientation, this is for the whole page and inside that create two linear layout with one of them for the vertical dashed line and inside that linear layout make a list of linear layout that consists of a '|' and ' '.

Aadi Droid
  • 1,689
  • 4
  • 22
  • 46
  • the whole layout would be a linearlayout, inside that you want say a dashed linear layout in the middle of the screen, so you create three child linear layout inside the primary one. In the middle linear layout you make a list of linearlayouts each having 2 views, one view contains "|" and the other view contains " ". So when you place all of them together it'll be a dashed line. Also the middle linear layour should have a orientation vertical. – Aadi Droid Feb 21 '12 at 05:27