0

The Source (aka The Illustration Of The Problem)

I have a ListView as follows:

<ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@android:color/transparent"
    android:dividerHeight="0px"
    android:listSelector="@android:color/transparent"
    android:id="@+id/hellyeah"
/>

Nothing too special about it. It sits inside a RelativeLayout.

The Problem

When running the app, I did notice a line between the list rows. So I hooked a debugger to the process, set a breakpoint on the onClick handler for the list rows, and started playing around in Android Studio's "Expression Evaluation" window:

((ListView) findViewById(R.id.hellyeah)).getDividerHeight();

If you've read the title of this question you'll know the result of this expression: -1.

But didn't I explicitely set it to 0 in the layout XML?

The Solution

Changing "0px" to "0dp" doesn't work. My question is not how to solve this - I could simply call setDividerHeight(0) and that works.

The Question

My question is: why isn't my android:dividerHeight="0px" respected? Why do I get a negative divider height?

Andrejovich
  • 544
  • 2
  • 13
  • 1
    I know this is not your question, but you can get rid of the dividers by specifying both divider="@null" and dividerHeight="0dip". I have no idea why you get the -1 value... – thelawnmowerman Feb 19 '14 at 15:20
  • 1
    The android code for `setDivider()` assigns `divider.getIntrinsicHeight()` to the divider height and by default `divider.getIntrinsicHeight()` returns -1, so that's probably the dry technical reason. This still does not explain why `0px` is not respected. It seems to be `setDividerHeight()` was not called by the XML parser – ilomambo Feb 19 '14 at 15:30
  • I observed the same with Android Studio and SDK Level 20 : I'm not able to totally remove the divider from XML, but there is no problem doing it from code! (http://www.buquet-net.com/cv/) – Nicolas Buquet Jul 18 '14 at 16:23
  • I cant remove divider not in xml, nor in code. Minimum is 1. :-( – djdance Jul 24 '14 at 10:52

0 Answers0