经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
Android MaterialCardView的使用介绍与示例
来源:jb51  时间:2021/11/9 15:50:48  对本文有异议

Android—MaterialCardView的使用

image

我们的征程是星辰大海,而非人间烟尘

文章目录 Android---MaterialCardView的使用演示xml布局其他的属性

演示

MDCard

xml布局

  1. <com.google.android.material.card.MaterialCardView
  2. android:id="@+id/materialCardView2"
  3. android:layout_width="170dp"
  4. android:layout_height="170dp"
  5. android:layout_marginLeft="20dp"
  6. android:layout_marginTop="20dp"
  7. android:clickable="true" // 是否可点击
  8. app:cardCornerRadius="20dp" // 圆角半径
  9. app:cardElevation="20dp" // 阴影范围
  10. app:layout_constraintStart_toStartOf="parent"
  11. app:layout_constraintTop_toBottomOf="@+id/banner"
  12. app:rippleColor="#A8C0EC" // 点击阴影特效的颜色
  13. app:state_dragged="true">
  14.  
  15. <ImageView
  16. android:layout_width="match_parent"
  17. android:layout_height="140dp"
  18. android:scaleType="centerCrop"
  19. android:src="@drawable/quesans" />
  20.  
  21. <TextView
  22. android:layout_width="match_parent"
  23. android:layout_height="30dp"
  24. android:layout_marginLeft="10dp"
  25. android:layout_marginTop="140dp"
  26. android:text="问答"
  27. android:textColor="@color/black"
  28. android:textFontWeight="@android:integer/config_mediumAnimTime"
  29. android:textSize="18sp" />
  30. </com.google.android.material.card.MaterialCardView>

image

其他的属性

特征 相关属性
Border app:strokeColor app:strokeWidth
Checkable android:checkable
Checked Icon app:checkedIcon app:checkedIconTint
Foreground Color app:cardForegroundColor
Ripple Color app:rippleColor

当然你还可以在Java/Kotlin代码中使用一些方法:

  1. void setCheckable (boolean checkable)//设置是否可以选择
  2. void setChecked (boolean checked)//选中的状态
  3. void setCheckedIcon (Drawable checkedIcon)//选中图标的样式
  4. void setCheckedIconResource (int id)//选中图标的样式
  5. void setDragged (boolean dragged)//是否可拖动
  6. void setRippleColor (ColorStateList rippleColor)//波纹效果的颜色
  7. void setStrokeColor (int strokeColor)//卡片边的颜色
  8. void setStrokeWidth (int strokeWidth)//卡片边的宽带
  9. void toggle ()//控制checkable的开关

到此这篇关于Android MaterialCardView的使用介绍与示例 的文章就介绍到这了,更多相关Android MaterialCardView内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号