
正文
CardView官方教程
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Create Cards
CardView
extends the
FrameLayout
class and lets you show information inside cards that have a consistent look across the platform.
CardView
widgets can have shadows and rounded corners.
To create a card with a shadow, use the
card_view:cardElevation
attribute.
CardView
uses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see Maintaining Compatibility.
Use these properties to customize the appearance of the
CardView
widget:
-
To set the corner radius in your layouts, use the
card_view:cardCornerRadiusattribute. -
To set the corner radius in your code, use the
CardView.setRadiusmethod. -
To set the background color of a card, use the
card_view:cardBackgroundColorattribute.
Figure 3 . Card examples.
The following code example shows you how to include a
CardView
widget in your layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
For more information, see the API reference for
CardView
.







