Android: List View alternating between 1px and 2px dividers

Have you faced a problem with Android ListView where the dividers alternate between 1 pixel and 2 pixel thickness although you have specifically styled it to 1px? I am sure many have, but for some reason they seem to ignore it. I say this because I noticed this problem in quite a few apps in the market. When I found the same problem in one of my apps, I decided to fix it although it was not at the top of my priority list.

1px_wrong

The first solution I came up with was more of a work-around. Instead of using a 1px divider line, I tried using a 1px thick image as @drawable. It worked out surprisingly well on my HTC Desire but was not without its own problems. On low-end android phones the dividers started to blink when the user scrolls the list. Sometimes they disappeared and never re-appeared. I guess it is some kind of a refresh problem. I even noticed this kind of behaviour in a few market apps. So, that approach didn’t work out very well…

Then after quite a bit of fiddling around, I found out the root cause of the problem. My app was running in compatibility mode!!! Man, how could I have not noticed that? Anyway, when I tried setting the minSdkVersion in my android manifest to version 4 and the targetSdkVersion to the version 8 the problem disappeared completely. I could now use a plain 1px divider line and there were no problems.

1px_right

  <uses-sdk android:minSdkVersion="4"
          android:targetSdkVersion="8"
    />

I just thought of sharing it with the world just in case someone runs into the same road block…

Ganeshji Marwaha

I spend my days as the Director of Technology for Mobility practice and help my clients design enterprise and consumer mobile strategies. Mobile Payments, Digital Wallet and Tokenization technologies are my areas of specialization

  • fish

    thanks a lot it is just in time for me because i face the same problem

  • Pulkit

    nice post.If I am not wrong after a long time you write something and its really nice again saved my time as i am new to Anaroid. I am your fan from the time i used your light weight script “JCarousel Lite”.

  • Ganeshji Marwaha

    @fish – Am glad you found it helpful. I took quite a while for me to figure that one out.

    @Pulkit – Really glad you found it useful. Also, yes, I have been on and off with my blog with various different priorities getting the better of me… Cool, so you use jcarousellite too???

  • Mason

    Thank you so much for taking the time to post this solution!

  • Thanks a lot man, I am having this issue for a long time, I googled a lot but didn’t get any proper help to rectify that. But u helped me, u saved me……

  • Ganeshji Marwaha

    @vivek – It’s my pleasure that I was able to help you

  • Clem

    Thanks a lot!!!
    I just wasted an entire day looking for the cause of this and finally here’s the answer. In my case it was an ExpandableListView (works as well).

  • Ganeshji Marwaha

    @Clem – Glad to have helped.

  • tidbeck

    This does not seem to cut it for me. Anything more I need to specify?

  • tidbeck

    Forget it. It works fine! Just removed some from may manifest.

  • narutoa yamazaki

    This is such a great information “Then after quite a bit of fiddling around, I found out the root cause of the problem. My app was running in compatibility mode!!! Man, how could I have not noticed that? Anyway, when I tried setting the minSdkVersion in my android manifest to version 4 and the targetSdkVersion to the version 8 the problem disappeared completely.” thanks for sharing….

    Background Check Rental

  • Great blog you have here, hope you wont mind if I retweet your blog posts to my twitters account. (:~)

    _____________

  • thanks allot…..it is workinggg fineee……

  • I am having this concern for years, I researched a lot but just didn’t get any appropriate help to fix that. But u assisted me, u stored me……

  • Thanks a lot man, I am having this problem for years, I researched a lot but just didn’t get any appropriate help to fix that. But u assisted me, u stored me