卡片式布局使用起来非常简单,首先在bulid.gradle文件中加入这么一句话compile 'com.android.support:cardview-v7:21.+',
然后就可以当做是其他控件来在你的xml文件中配置使用了
强调一点,一定是support.v7包下的cardview
案例如下
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="450dp"
card_view:cardBackgroundColor="#ffffff"
card_view:cardCornerRadius="25dp"
card_view:cardPreventCornerOverlap="true"
android:elevation="20dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:gravity="center"
android:orientation="vertical"
>
<EditText
android:layout_above="@+id/feedback"
android:id="@+id/phone"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="@drawable/edittext_background"
android:hint="请输入您的联系方式"
android:inputType="phone" />
<EditText
android:layout_above="@+id/commit"
android:layout_marginBottom="25dp"
android:layout_marginTop="20dp"
android:gravity="left"
android:id="@+id/feedback"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/edittext_background"
android:hint="请输入您的宝贵意见"
android:padding="10dp"
android:lines="10"
/>
<Button
android:id="@+id/commit"
style="@style/textSytle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:onClick="commit"
android:text="提交" />
</LinearLayout>
</android.support.v7.widget.CardView>