学习使用Material Design控件(三)使用CardView实现卡片效果

 更新时间:2017年07月28日 10:00:07   作者:贵公子  
这篇文章主要为大家介绍了学习使用Material Design控件的详细教程,如何使用CardView实现卡片效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文主要介绍CardView的使用,CardView是继承自FrameLayout,使用比较简单,只需要用CardView包含其他View就可以实现卡片效果了。

实现效果如下:


加入依赖库

dependencies {
  ….
  compile 'com.android.support:cardview-v7:22.2.0'
}

Layout布局

 <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        android:layout_marginBottom="@dimen/card_margin"
        android:layout_marginLeft="@dimen/card_margin"
        android:layout_marginRight="@dimen/card_margin">

        <LinearLayout
          style="@style/CardView.Content"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal">

          <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/book1" />

          <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:orientation="vertical">

            <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/book_title_1"
              android:textAppearance="@style/TextAppearance.AppCompat.Title"
              android:textColor="@color/primary_text" />

            <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="2dp"
              android:text="@string/book_description_1"
              android:textColor="@color/secondary_text" />
          </LinearLayout>

        </LinearLayout>

</android.support.v7.widget.CardView>

app:cardBackgroundColor 设置CardView背景颜色
app:cardCornerRadius 设置CardView圆角大小
app:cardElevation 设置CardView阴影高度

项目源码已发布到Github,以后慢慢加入其他控件的使用。
 源码地址:MaterialDesignExample

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 手机方向传感器的缺点及解决方法探究

    手机方向传感器的缺点及解决方法探究

    今天小编就为大家分享一篇关于手机方向传感器的缺点及解决方法探究,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • android查看网络图片的实现方法

    android查看网络图片的实现方法

    这篇文章主要为大家详细介绍了android查看网络图片的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-04-04
  • Android仿QQ未读消息--红点拖拽删除【源代码】

    Android仿QQ未读消息--红点拖拽删除【源代码】

    本文Demo是一款仿qq未读消息拖拽删除的例子,继承RelativeLayout的WaterDrop实现了圆形图标功能;继承ImageView的CircleImageView圆形图片功能。效果非常不错,很适合有圆形设计的朋友参考
    2017-04-04
  • Android编程之OpenGL绘图技巧总结

    Android编程之OpenGL绘图技巧总结

    这篇文章主要介绍了Android编程之OpenGL绘图技巧,结合实例形式总结分析了Android基于OpenGL绘图的原理与具体步骤,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-11-11
  • Android事件分发机制(下) View的事件处理

    Android事件分发机制(下) View的事件处理

    这篇文章主要介绍了Android事件分发机制下篇, View的事件处理的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-01-01
  • Android多媒体之VideoView视频播放器

    Android多媒体之VideoView视频播放器

    这篇文章主要为大家详细介绍了Android多媒体之VideoView视频播放器的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-02-02
  • android app跳转应用商店实现步骤

    android app跳转应用商店实现步骤

    这篇文章主要为大家介绍了android app跳转应用商店实现步骤详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-11-11
  • 深入了解Android Okio的超时机制

    深入了解Android Okio的超时机制

    Okio是一个IO库,底层基于Java原生的输入输出流实现。但原生的输入输出流并没有提供超时的检测机制。而Okio实现了这个功能,本文就来为大家详细讲讲
    2023-02-02
  • 详解Android Automotive车载应用对驾驶模式Safe Drive Mode的适配

    详解Android Automotive车载应用对驾驶模式Safe Drive Mode的适配

    这篇文章主要介绍了详解Android Automotive车载应用对驾驶模式(Safe Drive Mode)的适配,对车载应用感兴趣的同学可以参考下
    2021-04-04
  • Android BroadcastReceiver广播机制概述

    Android BroadcastReceiver广播机制概述

    这篇文章主要为大家详细介绍了Android BroadcastReceiver广播机制,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-08-08

最新评论