1

I have to design a layout having gridview with dashed/dotted separator. Can anyone please do let me know how can I do it?

This question may resemble to another question asked here in stackoverflow, but it's different because:

A] I need a dotted line

B] The dotted line shouldn't touch the edge of cell which can't be done based on the answer given at that question.

Grid layout with dotted/dashed separator

Community
  • 1
  • 1
sUndeep
  • 362
  • 3
  • 16
  • post your xml where you created parent layout – N J Sep 21 '15 at 13:04
  • you can make a the the bottom and right of your row with a background repeat image and remove the normal divider... that would duplicate the small dot/dash to complete the width of the gridview. Keep in mind that the height must be like 2dp. – Mariano Zorrilla Sep 21 '15 at 13:05
  • possible duplicate of [Android GridView draw dividers](http://stackoverflow.com/questions/7132030/android-gridview-draw-dividers) – Chintan Rathod Sep 21 '15 at 13:08
  • Hi @MarianoZorrilla, Thanks for your reply. If I will follow your answer, then at the right side of each cell, one vertical bar will get added. But you can see at the right of 2nd cells vertical bar is not there as per my requirement. So still if I am trying to hide it at getView() method based on condition (pos%2 !=0), I am getting recycling issue. – sUndeep Sep 21 '15 at 14:46
  • Hi @Chintan Rathod, thanks for the reference link. My question is similar to that, I tried to integrate, but it didn't resolve my UI requirement. You can see my edited question now. – sUndeep Sep 21 '15 at 14:47
  • @sUndeep check this answer... may help you: http://stackoverflow.com/a/22555548/3743245 – Mariano Zorrilla Sep 21 '15 at 15:03

1 Answers1

1

you can try below code:

drawable/dotted_shape.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="15px"
       android:dashGap="15px"
       android:width="2dp"/>
</shape>

this will give you dotted line separator. Thanks.

  • Hi Android WeblineIndia, thanks for your quick answer. But if you apply this drawable as background of grid item, then it'll cover the four sides of cell with dotted line and it will look odd at the center area. – sUndeep Sep 21 '15 at 14:41
  • this was an example of how to show dotted border, now if you just want to show border on a particular side than you need to manage with layer list , see this example: –  Sep 22 '15 at 06:32
  • How can I adjust it in such a way that for cell 0, right border will come and for cell 1 right border will not come. – sUndeep Sep 22 '15 at 07:15