美文网首页
CardView的使用

CardView的使用

作者: 仍是少年呀 | 来源:发表于2016-10-13 13:20 被阅读69次
  • 添加依赖
compile 'com.android.support:cardview-v7:21.0.+'```

- 创建卡片
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
 扩展 [FrameLayout](https://developer.android.com/reference/android/widget/FrameLayout.html)类别并让您能够显示卡片内的信息,这些信息在整个平台中拥有一致的呈现方式。
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)小组件可拥有阴影和圆角。
如果要使用阴影创建卡片,请使用 card_view:cardElevation属性。
[CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)在 Android 5.0(API 级别 21)及更高版本中使用真实高度与动态阴影,而在早期的 Android 版本中则返回编程阴影实现。如需了解详细信息,请参阅[保持兼容性](https://developer.android.com/training/material/compatibility.html)
使用这些属性定制 [CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
 小组件的外观:
如果要在您的布局中设置圆角半径,请使用 card_view:cardCornerRadius属性。
如果要在您的代码中设置圆角半径,请使用 CardView.setRadius方法。
如果要设置卡片的背景颜色,请使用 card_view:cardBackgroundColor属性。

下列代码示例将展示如何将 [CardView](https://developer.android.com/reference/android/support/v7/widget/CardView.html)
 小组件包括在您的布局中:
```xml
<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>```

注:以上部分大多翻译自google的官网,为了没梯子的同志们着想,搬过来。

相关文章

网友评论

      本文标题:CardView的使用

      本文链接:https://www.haomeiwen.com/subject/dzuwyttx.html