对于 api < 14,分隔符在 LinearLayoutCompat 中不可见
Dividers are not visible in LinearLayoutCompat for api < 14
由于 LinearLayout 仅在 api 14 中添加了分隔符,并且此功能在支持库中作为 LinearLayoutCompat class 向后移植,因此将其用于列表或在布局子项之间轻松添加分隔符非常方便。
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>
api 11+ 设备一切正常,但在旧设备上不显示分隔符。如何修复?
我认为这是由 LayoutInflater 实例化的 GradientDrawable 中的一个错误,可以通过将 "solid" 替换为具有相同颜色的假 "gradient" 参数来修复它,现在它可以工作了。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="1dp" />
<gradient android:startColor="#44000000" android:endColor="#44000000/>
</shape>
由于 LinearLayout 仅在 api 14 中添加了分隔符,并且此功能在支持库中作为 LinearLayoutCompat class 向后移植,因此将其用于列表或在布局子项之间轻松添加分隔符非常方便。
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>
api 11+ 设备一切正常,但在旧设备上不显示分隔符。如何修复?
我认为这是由 LayoutInflater 实例化的 GradientDrawable 中的一个错误,可以通过将 "solid" 替换为具有相同颜色的假 "gradient" 参数来修复它,现在它可以工作了。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="1dp" />
<gradient android:startColor="#44000000" android:endColor="#44000000/>
</shape>