CardView, like RecyclerView , is a new control after Android 5.0, born with Material Design.
1. Introducing CardView
CardView components need to be used in new AS projects. Like RecyclerView, CardView components need to be added in Gradle in advance.
package , directly in Gradle:
compile 'com.android.support:cardview-v7:25.3.1' (The version number of CardView is the same as the version number of V7 in the project)
Or enter CardView in Library dependence and select the one under the V7 package.
2. Why use CardView
CardView is a layout control inherited from FramLayout. The note on CardView in the official website is:
A FrameLayout with a rounded corner background and shadow. (CardView is FramLayout with rounded corners and shadow)
In the past, we needed to customize Shape to achieve rounded corners and shadow effects; now, these effects are integrated into CardView properties. at the same time,
CardView should be used when displaying hierarchical content, and should be selected when displaying lists or grids, as these edges allow the user to
It's easier to differentiate between these.
3. CardView property
app:cardBackgroundColor sets the background color
app: cardCornerRadius sets the size of the rounded corners
app: cardElevation sets the z-axis shadow height
app: cardMaxElevation Set the maximum height value of the z-axis
app: contentPadding The space between the content and the margin
app: contentPaddingLeft content and left padding
app: contentPaddingTop The space between the content and the top
app: contentPaddingRight The space between the content and the right
app: contentPaddingBottom The space between the content and the bottom
app:paddingStart The space between the content and the padding starts
app:paddingEnd content and padding end
app: cardUseCompatPadding Set padding, API21 and above versions still have the same calculation method as previous versions
app: cardPreventConrerOverlap Add padding in API 20 and below. This property is to prevent overlapping of content and corners
Note: Using android:background to set the background color in CardView is invalid.
Ps: One more thing, sometimes some people rename the property names in CardView in order to highlight these properties are used in CardView,
For example: xmlns:card_view=”http://schemas.android.com/apk/res-auto”, then the app will become card_view, but
Using the app directly does not affect anything, just a change in the attribute prefix name.
4. Click on CardView to appear Ripple effect
Add to the CardView layout: android:foreground=”?android:attr/selectableItemBackground” to achieve
Click on the CardView to have a ripple effect.
Links:
CardView, like RecyclerView , is a new control after Android 5.0, born with Material Design.
1. Introducing CardView
CardView components need to be used in new AS projects. Like RecyclerView, CardView components need to be added in Gradle in advance.
package , directly in Gradle:
compile 'com.android.support:cardview-v7:25.3.1' (The version number of CardView is the same as the version number of V7 in the project)
Or enter CardView in Library dependence and select the one under the V7 package.
2. Why use CardView
CardView is a layout control inherited from FramLayout. The note on CardView in the official website is:
A FrameLayout with a rounded corner background and shadow. (CardView is FramLayout with rounded corners and shadow)
In the past, we needed to customize Shape to achieve rounded corners and shadow effects; now, these effects are integrated into CardView properties. at the same time,
CardView should be used when displaying hierarchical content, and should be selected when displaying lists or grids, as these edges allow the user to
It's easier to differentiate between these.
3. CardView property
app:cardBackgroundColor sets the background color
app: cardCornerRadius sets the size of the rounded corners
app: cardElevation sets the z-axis shadow height
app: cardMaxElevation Set the maximum height value of the z-axis
app: contentPadding The space between the content and the margin
app: contentPaddingLeft content and left padding
app: contentPaddingTop The space between the content and the top
app: contentPaddingRight The space between the content and the right
app: contentPaddingBottom The space between the content and the bottom
app:paddingStart The space between the content and the padding starts
app:paddingEnd content and padding end
app: cardUseCompatPadding Set padding, API21 and above versions still have the same calculation method as previous versions
app: cardPreventConrerOverlap Add padding in API 20 and below. This property is to prevent overlapping of content and corners
Note: Using android:background to set the background color in CardView is invalid.
Ps: One more thing, sometimes some people rename the property names in CardView in order to highlight these properties are used in CardView,
For example: xmlns:card_view=”http://schemas.android.com/apk/res-auto”, then the app will become card_view, but
Using the app directly does not affect anything, just a change in the attribute prefix name.
4. Click on CardView to appear Ripple effect
Add to the CardView layout: android:foreground=”?android:attr/selectableItemBackground” to achieve
Click on the CardView to have a ripple effect.
Links: