curioushikhov
curioushikhov

Reputation: 2828

Dividers are not visible in LinearLayoutCompat for api < 14

Since LinearLayout added dividers only in api 14 and this feature was backported in support library as LinearLayoutCompat class it is very handy to use it for lists or easily add spacers between layout childs.

layout/layout.xml:

<android.support.v7.widget.LinearLayoutCompat
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:divider="@drawable/divider"
    app:showDividers="middle"
    />

drawable/divider.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="1dp" />
    <solid android:color="#44000000"/>
</shape>

All is fine for api 11+ devices, but on older devices divider is not shown. How to fix?

Upvotes: 1

Views: 1540

Answers (1)

curioushikhov
curioushikhov

Reputation: 2828

I think this is a bug in GradientDrawable which is instantiated by LayoutInflater, it can be fixed by replacing "solid" with fake "gradient" parameter with the same colors and it works now.

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:height="1dp" />
    <gradient android:startColor="#44000000" android:endColor="#44000000/>
</shape>

Upvotes: 2

Related Questions