卡片,其实就是一张背景图片,但做也还需要注意一点。

错误做法:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <LinearLayout
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:orientation="vertical"
  11. android:background="@drawable/selector_list_item_bg"
  12. android:padding="5dp"
  13. >
  14.  
  15. </LinearLayout>
  16.  
  17. </LinearLayout>

只需要轻轻的把padding改成margin即可。因为卡片其实就是用里面的线性布局跟外面的线性布局之间生成一定的间距才形成。

正确做法:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6.  
  7. <LinearLayout
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_margin="5dp"
  11. android:background="@drawable/selector_list_item_bg"
  12. android:orientation="vertical" >
  13. </LinearLayout>
  14.  
  15. </LinearLayout>

完整布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. >
  7.  
  8. <LinearLayout
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_marginLeft="5dp"
  12. android:layout_marginRight="5dp"
  13. android:background="@drawable/selector_list_item_bg"
  14. android:orientation="vertical" >
  15.  
  16. <RelativeLayout
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:padding="10dp" >
  20.  
  21. <ImageView
  22. android:id="@+id/iv_icon"
  23. android:layout_width="45dp"
  24. android:layout_height="45dp"
  25. android:layout_centerVertical="true"
  26. android:layout_marginRight="10dp"
  27. android:src="@drawable/ic_default" />
  28.  
  29. <TextView
  30. android:id="@+id/tv_name"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:layout_toRightOf="@+id/iv_icon"
  34. android:text="应用名称"
  35. android:textColor="#000"
  36. android:textSize="18sp" />
  37.  
  38. <RatingBar
  39. android:id="@+id/rb_bar"
  40. android:layout_width="wrap_content"
  41. android:layout_height="15dp"
  42. android:layout_below="@+id/tv_name"
  43. android:isIndicator="true"
  44. android:layout_marginTop="5dp"
  45. android:layout_toRightOf="@+id/iv_icon"
  46. android:progressDrawable="@drawable/custom_ratingbar"
  47. android:rating="2" />
  48.  
  49. <TextView
  50. android:id="@+id/tv_size"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:layout_below="@+id/rb_bar"
  54. android:layout_toRightOf="@+id/iv_icon"
  55. android:text="3.7MB"
  56. android:textColor="#5000"
  57. android:textSize="16sp" />
  58.  
  59. <LinearLayout
  60. android:layout_width="wrap_content"
  61. android:layout_height="wrap_content"
  62. android:layout_alignParentRight="true"
  63. android:layout_centerVertical="true"
  64. android:gravity="center"
  65. android:orientation="vertical" >
  66.  
  67. <ImageView
  68. android:id="@+id/iv_download"
  69. android:layout_width="wrap_content"
  70. android:layout_height="wrap_content"
  71. android:src="@drawable/ic_download" />
  72.  
  73. <TextView
  74. android:id="@+id/tv_download"
  75. android:layout_width="wrap_content"
  76. android:layout_height="wrap_content"
  77. android:text="下载"
  78. android:textColor="#000"
  79. android:textSize="18sp" />
  80. </LinearLayout>
  81. </RelativeLayout>
  82.  
  83. <View
  84. android:layout_width="match_parent"
  85. android:layout_height="0.2dp"
  86. android:background="#2000" />
  87.  
  88. <TextView
  89. android:id="@+id/tv_des"
  90. android:layout_width="wrap_content"
  91. android:layout_height="wrap_content"
  92. android:padding="5dp"
  93. android:singleLine="true"
  94. android:text="巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉巴拉巴拉拉"
  95. android:textColor="#5000" />
  96. </LinearLayout>
  97.  
  98. </LinearLayout>

listview的条目(item)如何做出卡片效果的更多相关文章

  1. listview指定某item的点击效果

    需求:listview的某些item能够点击,需要点击效果,有些item不能点击,需要屏蔽点击效果. 实现: 1.layout: <ListView android:id="@+id/ ...

  2. Listview的条目item内的点击响应事件

    还是这张图 这里的历史列表就是一个ListView,抛开该界面中ScrollView或者RecycleView与该ListView会有冲突,所谓的冲突,说白了就是父控件与子控件两者间的关系冲突,该冲突 ...

  3. Android SwipeToDismiss:左滑/右滑删除ListView条目Item

     <Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(githu ...

  4. Android中Listview点击item不变颜色以及设置listselector 无效

    Android中Listview点击item不变颜色以及设置listselector 无效 这是同一个问题,Listview中点击item是会变颜色的,因为listview设置了默认的listsele ...

  5. Android ListView实现单击item出现删除按钮以及滑动出现删除按钮

    我自己一个人弄的公司的产品客户端,所以还是想记录下来以免忘记或者丢失... 在我的上一篇博文(点击打开链接)是一个文件管理的东西,基础组件也是ListView所以在此只是改动一下而已. 单击: 点击出 ...

  6. RN中listView的每个item等高

    今天写ListView的每个Item的布局的时候发现,当文字太长时被截掉了不能完全显示,检查了很久发现没有设置固定高度都是可伸缩的为什么没有伸缩呢.看了很久才发现每个item是等高的,于是仔细检查才看 ...

  7. ListView遍历每个Item出现NullPointerException的异常

    在使用ListView过程中我们有时候需要遍历取得每个Item项中的一些数据(比如每个Item里面有TextView,需要获取它的文本等等),但是我们在遍历过程中经常会遇到NullPointerExc ...

  8. ListView遍历每个Item出现NullPointerException的异常(转)

    在使用ListView过程中我们有时候需要遍历取得每个Item项中的一些数据(比如每个Item里面有TextView,需要获取它的文本等等),但是我们在遍历过程中经常会遇到NullPointerExc ...

  9. Android ListView实现不同item的方法和原理分析

    ListView实现不同item的方法和原理分析 一问题抛出Listview是android里面的重要组件,用来显示一个竖向列表,这个没有什么问题:但是有个时候列表里面的item不是一样的,如下图,列 ...

随机推荐

  1. sql server显示某一列中有重复值的行

    sql server查询一张表 ,显示某一列中有重复值的行,可以这样写: Select * From 表名 where 列名 in(Select 列名 From Table group by 列名 h ...

  2. 《C++ Primer》之面向对象编程(三)

    继承情况下的类作用域 在继承情况下,派生类的作用域嵌套在基类作用域中.如果不能在派生类作用域中确定名字,就在外围基类作用域中查找该名字的定义.正是这种类作用域的层次嵌套使我们能够直接访问基类的成员,就 ...

  3. Edit Individual GridView Cells in ASP.NET

    Edit individual GridView cells without putting the entire row into edit mode.Examples using the SqlD ...

  4. git基本命令--远程

    git clone: # clone到 <本地目录名> $ git clone <版本库的网址> <本地目录名> # 克隆版本库的时候,所使用的远程主机自动被Git ...

  5. hdu_2224_The shortest path(dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2224 题意:双调欧几里德旅行商经典问题,找一条最短回路使得该路经过所有的点 题解:dp[i][j]=d ...

  6. 利用DataImportHandler建索引时一直无法完成

    问题研究 项目中需要利用DataImportHandler从hive中sync数据到solr.发现有时候hive sql已经执行完几个小时了,sync任务还没有完成,貌似哪里卡住了.重启solr后重新 ...

  7. js获取不同浏览器盒子宽度高度

    DTD 已声明 IE document.documentElement.scrollHeight 浏览器所有内容高 度 ,document.body.scrollHeight 浏览器所有内容高度 do ...

  8. table新增空白行到首行

    var str=""; str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff'>"; str+=&quo ...

  9. 很好的容斥思想 HDU 5514

    题目描述:有n只青蛙,m个石头(围成圆圈).第i只青蛙每次只能条a[i]个石头,问最后所有青蛙跳过的石头的下标总和是多少? 思路:经过绘图我们发现,每次跳过的位置一定是k*gcd(a[i], m).然 ...

  10. 文件描述符和exec() close_on_exec

    #include <fcntl.h> #include <iostream> #include <unistd.h> using namespace std; in ...