热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android5.0新特性——CardView使用

一、cardView1.什么是CardView?卡片布局2.CardView常用属性app:cardBackgroundColor这是设置背景颜色a

一、 cardView

  1.什么是CardView?

    卡片布局

  2.CardView常用属性

    app:cardBackgroundColor这是设置背景颜色 
    app:cardCornerRadius这是设置圆角大小 
    app:cardElevation这是设置z轴的阴影 
    app:cardMaxElevation这是设置z轴的最大高度值 
    app:cardUseCompatPadding是否使用CompatPadding 
    app:cardPreventCornerOverlap是否使用PreventCornerOverlap 
    app:contentPadding 设置内容的padding 
    app:contentPaddingLeft 设置内容的左padding 
    app:contentPaddingTop 设置内容的上padding 
    app:contentPaddingRight 设置内容的右padding 
    app:contentPaddingBottom 设置内容的底padding

 

 

二、配置cardview 环境

1.导入cardView的包

  

 

 

cardview 包路径

  

cardView 环境就配好了 注意:修改环境工程的名字,我这改为cardview_lib

三、创建项目

  1.创建 android 工程,注意: android版本必须是5.0以上才能使用cardview

  2.关联cardview 环境 (右键项目选择Properties)

   

 

 

 3.编写代码

  xml配置:

    

  1 <android.support.v7.widget.CardView  
  2     xmlns:android="http://schemas.android.com/apk/res/android"  
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     android:layout_width="fill_parent"  
  5     android:layout_height="90dp"  
  6     android:clickable="true"  
  7     android:foreground="?android:attr/selectableItemBackground"  
  8     app:cardElevation="4dp"  
  9     app:cardBackgroundColor="#ffffff"  
 10     app:cardCornerRadius="4dp"  
 11     app:cardUseCompatPadding="true"
 12     app:contentPadding="5dp"
 13     app:contentPaddingTop="10dp"
 14     app:contentPaddingLeft="5dp"
 15     app:contentPaddingBottom="10dp">
 16 
 17     <LinearLayout
 18         android:layout_width="match_parent"
 19         android:layout_height="match_parent" >
 20 
 21         <ImageView
 22             android:id="@+id/shool_image"
 23             android:layout_width="50dp"
 24             android:layout_height="50dp"
 25             android:background="#f2f2f2"
 26             android:src="@drawable/ic_launcher" />
 27 
 28         <LinearLayout
 29             android:layout_width="match_parent"
 30             android:layout_height="match_parent"
 31             android:layout_weight="1"
 32             android:orientation="vertical" 
 33             android:layout_marginLeft="10dp"
 34             android:background="#ffffff">
 35 
 36             <TextView
 37                 android:id="@+id/shool_name"
 38                 android:layout_width="wrap_content"
 39                 android:layout_height="18dp"
 40                 android:gravity="center"
 41                 android:layout_gravity="left"
 42                 android:text="北京师范大学" 
 43                 android:textStyle="bold"
 44                 android:layout_marginTop="6dp"
 45                 android:textColor="#666666"/>
 46 
 47             <LinearLayout
 48                 android:layout_width="fill_parent"
 49                 android:layout_height="wrap_content" 
 50                 android:layout_marginTop="5dp">
 51                 <LinearLayout
 52                     android:layout_width="match_parent"
 53                     android:layout_height="match_parent"
 54                     android:layout_weight="1" >
 55 
 56                     <TextView
 57                         android:layout_width="wrap_content"
 58                         android:layout_height="wrap_content"
 59                         android:text="城市:"
 60                         android:textColor="#7F7F7F"
 61                         android:textSize="12sp" />
 62 
 63                     <TextView
 64                         android:id="@+id/shool_city"
 65                         android:layout_width="wrap_content"
 66                         android:layout_height="wrap_content"
 67                         android:text="珠海市"
 68                         android:textColor="#7F7F7F"
 69                         android:textSize="12sp" />
 70                 LinearLayout>
 71                 <LinearLayout
 72                     android:layout_width="match_parent"
 73                     android:layout_height="match_parent"
 74                     android:layout_weight="1" >
 75 
 76                     <TextView
 77                         android:layout_width="wrap_content"
 78                         android:layout_height="wrap_content"
 79                         android:text="学历要求:"
 80                         android:textColor="#7F7F7F"
 81                         android:textSize="12sp" />
 82 
 83                     <TextView
 84                         android:id="@+id/shool_xueli"
 85                         android:layout_width="wrap_content"
 86                         android:layout_height="wrap_content"
 87                         android:text="本科"
 88                         android:textColor="#7F7F7F"
 89                         android:textSize="12sp" />
 90                 LinearLayout>
 91 
 92                 <LinearLayout
 93                     android:layout_width="match_parent"
 94                     android:layout_height="match_parent"
 95                     android:layout_weight="1" >
 96 
 97                     <TextView
 98                         android:layout_width="wrap_content"
 99                         android:layout_height="wrap_content"
100                         android:text="校招会:"
101                         android:textColor="#7F7F7F"
102                         android:textSize="12sp" />
103 
104                     <TextView
105                         android:id="@+id/shool_xzh"
106                         android:layout_width="wrap_content"
107                         android:layout_height="wrap_content"
108                         android:text="5场"
109                         android:textColor="#7F7F7F"
110                         android:textSize="12sp" />
111                 LinearLayout>
112                 
113             LinearLayout>
114         LinearLayout>
115     LinearLayout>
116 android.support.v7.widget.CardView>

 

 运行效果就如上图一样

 


推荐阅读
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 2021年最详细的Android屏幕适配方案汇总
    1Android屏幕适配的度量单位和相关概念建议在阅读本文章之前,可以先阅读快乐李同学写的文章《Android屏幕适配的度量单位和相关概念》,这篇文章 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 今日份分享:Flutter自定义之旋转木马
    今日份分享:Flutter自定义之旋转木马-先上图,带你回到童年时光:效果分析子布局按照圆形顺序放置且平分角度子布局旋转、支持手势滑动旋转、快速滑动抬手继续旋转、自动旋转支持X轴旋 ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • SmartRefreshLayout自定义头部刷新和底部加载
    1.添加依赖implementation‘com.scwang.smartrefresh:SmartRefreshLayout:1.0.3’implementation‘com.s ... [详细]
  • 在一对一直播源码使用过程中,有时会出现软键盘切换闪屏问题,就是当切换表情的时候屏幕会跳动,因此要对一对一直播源码表情面板无缝切换进行优化。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 在开发app时,使用了butterknife后,在androidStudio打包apk时可能会遇到报错。为了解决这个问题,可以通过打开proguard-rules.pro文件进行代码混淆来解决。本文介绍了具体的混淆代码和方法。 ... [详细]
  • 近来有一个需求,是需要在androidjava基础库中插入一些log信息,完成这个工作需要的前置条件有编译好的android源码具体android源码如何编译,这 ... [详细]
  • 当我在doWork方法中运行代码时,通过单击button1,进度条按预期工作.但是,当我从其他方法(即btn2,btn3)将列表传递给doWork方法时,进度条在启动后会跳转到10 ... [详细]
  • 这两天用到了ListView,写下遇到的一些问题。首先是ListView本身与子控件的焦点问题,比如我这里子控件用到了Button,在需要ListView中的根布局属性上加上下面的这一个属性:and ... [详细]
author-avatar
null5269
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有