閉じる

android.support.v7.widget.CardView

android.support.v7.cardviewをインポートすると使えるようになる。

んーと、単に角が丸いだけのビュー?

背景色を指定するには cardBackgroundColorを指定する。

長押ししたときなどにフィードバックが欲しいなら foregroundを指定する。*1

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardBackgroundColor="@color/ImageGridItem_bg"
card_view:cardCornerRadius="20dp">
</android.support.v7.widget.CardView>

cardCornerRadiusの値が大きめにすると背景色を指定したときに 9-patchの分割位置みたいなところに線が入るのは何故だろう?

2014/11/04追記

線が入る現象は大きい値だと目立つと言うだけで、5dp程度でも見える。
けど、contentPaddingに適切な値を指定しないと発生するみたい。

cardBackgroundColorに透過指定を持った色を指定すると描画がおかしくなるっぽく。

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="?attr/colorPrimaryDark"
app:cardCornerRadius="5dp"
app:contentPadding="2dp"
tools:ignore="NewApi" >
</android.support.v7.widget.CardView>

*1 3.0以降だったと思うけど、さすがにそろそろ 2.xは切っても良いと思う。

コメントを残す

メールアドレスが公開されることはありません。必須項目には印がついています *

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)