3

I have a line shape, it is a thick line:

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="30">
    <shape android:shape="line">
        <size
            android:width="100dp"
            android:height="100dp" />
        <stroke
            android:width="30dp"
            android:color="#0000FF" />
    </shape>
</rotate>

I am wondering is there any way to make the line's two ends rounded?

I tried adding this to above <shape>:

<corners android:radius="10dp"/>

But it doesn't take any effect for thick line.

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

4

Add a View tag in your xml something like this which represents the line. Adjust the height for varying thickness of the line.

<View
   android:layout_width="100dp"
   android:layout_height="10dp"
   android:background="@drawable/test"/>

And then add the usual background for it like you've done

test.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#000000" />
<corners android:radius="8dip" />
</shape>

This first gave me no start tag found error but on clean and rebuild it produced the required output. Try it. Hope this helps.

Nobody
  • 397
  • 1
  • 5
  • 25
  • Please try my code, I changed to rectangle, and height 1 dp, my line disappears. – Leem.fin Jan 15 '17 at 19:02
  • Sorry I'm afk, just try giving a background color and see if you can see the line. If you don't I'll try and update the solution. – Nobody Jan 15 '17 at 19:04
  • no...can't see, & one more problem, if I have a short line with current height, it looks like a diamond than a line. – Leem.fin Jan 15 '17 at 19:08
  • Okay then adding a View element in xml with height and width 1dp will you give you a proper line short or long and then,add your code above with the radius as the view's background. I'll update the code in 5 mins, adjust view's width to make it thick – Nobody Jan 15 '17 at 19:13