Проблема
Вот пример когда, где тень не появляется, хотя свойство card_view:cardElevation прописано
Java: Layout.xml
- ...
- <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
- android:id="@+id/card_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- card_view:cardCornerRadius="10dp"
- card_view:cardElevation="4dp"
- >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <ImageView
- android:id="@+id/item_image"
- android:layout_width="match_parent"
- android:layout_height="98dp"
- android:scaleType="centerCrop"
- android:cropToPadding="false"
- app:srcCompat="@android:drawable/ic_menu_help" />
- <TextView
- android:id="@+id/item_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Название"
- android:textAlignment="center" />
- <TextView
- android:id="@+id/item_description"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Описание"
- android:textAlignment="center" />
- </LinearLayout>
- </android.support.v7.widget.CardView>
- ...
Решение очень простое!
Привет! Все очень просто. Чтобы была видна тень - вокруг CardView должно быть свободное пространство. Следуя Material Design - оно должно равняться 8dp.
Правильный код с свойством android:layout_margin
Java
- ...
- <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
- android:id="@+id/card_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- card_view:cardCornerRadius="10dp"
- card_view:cardElevation="4dp"
- android:layout_margin="8dp"
- >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <ImageView
- android:id="@+id/item_image"
- android:layout_width="match_parent"
- android:layout_height="98dp"
- android:scaleType="centerCrop"
- android:cropToPadding="false"
- app:srcCompat="@android:drawable/ic_menu_help" />
- <TextView
- android:id="@+id/item_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Название"
- android:textAlignment="center" />
- <TextView
- android:id="@+id/item_description"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Описание"
- android:textAlignment="center" />
- </LinearLayout>
- </android.support.v7.widget.CardView>
- ...
Comments