CardViewを作成する際、Lollipopより前の端末だと、カード周りに余白が入ってしまいます。
もともと余白のあるデザインであればそんなに気になりませんが、ImageViewをカードいっぱいに持つデザインの場合には調整が必要です。
Lollipop以降 | Lollipopより前 |
---|---|
対応
SupportLibraryのバージョンが24.2.0以降であれば、CardViewへ
app:cardPreventCornerOverlap="false"
を追加するとLollipopより前の端末でも余白がなくなります。
公式によると、「Lollipopより前の端末ではカードの角丸とカード上のViewの境界が重なるのを避けるために、勝手にPaddingを追加するよ」とあり、falseにするとPaddingを追加しなくなります。
On pre-Lollipop platforms, CardView does not clip the bounds of the Card for the rounded corners. Instead, it adds padding to content so that it won't overlap with the rounded corners. You can disable this behavior by setting this field to false.
注意:これでPaddingはなくなるのですが、ImageViewが角丸になるわけではないので、RoundedImageViewライブラリを使うなどして角丸にしてあげる必要があります。
補足
上記オプションは、Lollipop以降の端末には基本的に影響がありません。app:cardUseCompatPadding="true"
を指定して、Lollipop前の挙動に設定している場合には、影響を受けます。
Setting this value on Lollipop and above does not have any effect unless you have enabled compatibility padding.