[关闭]
@cxm-2016 2016-08-29T07:10:42.000000Z 字数 1051 阅读 1778

创建卡片样式布局

android no


如何添加

1,在你的build.gradle文件中添加cardview

  1. dependencies {
  2. compile 'com.android.support:cardview-v7:X.X.X' // where X.X.X version
  3. }

2,声明你的卡片布局layout.xml.

  1. <android.support.v7.widget.CardView
  2. android:layout_width="match_parent"
  3. android:layout_height="200dp">
  4. <TextView
  5. android:text="Hello World!"
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"/>
  8. </android.support.v7.widget.CardView>

Use android:clipToPadding="false" on the card parent allows you to prevent posible clips in the outer shadows of the card.

如何自定义布局

1,在styles.xml文件中声明你的样式.

  1. <style name="MyCardViewStyle" parent="Theme.AppCompat.Light">
  2. <item name="cardCornerRadius">2dp</item>
  3. <item name="cardElevation">2dp</item>
  4. <item name="contentPaddingBottom">24dp</item>
  5. <item name="contentPaddingTop">24dp</item>
  6. <item name="contentPaddingLeft">16dp</item>
  7. <item name="contentPaddingRight">16dp</item>
  8. <item name="cardBackgroundColor">@color/indigo</item>
  9. </style>

2,通过style属性来应用你的样式.

  1. <android.support.v7.widget.CardView
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. style="@style/MyCardViewStyle">
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注