android 5.0新增加的一个控件CardView,在support v7兼容包中,意思就是卡片View,虽然可以设置阴影,圆角等等样式,但是我们也可以自己写出来,谷歌工程师之所以出这个,肯定是帮我们做了很多事情,在性能和兼容性各方面还是做了工作的。之前也有用过Listview,后来发现自己写的样式有点不堪,所以还是在项目中用了这玩意,今天我就来写写这玩意在Xamarin Android如何使用CardView呢?主要看一下下面三个例子

  • CardView的简单使用
  • 使用SeekBar来改变CardView的样式
  • CardView与ListView的连用

Xamarin Android CardView简单使用

Cardview要引入support.v7兼容包,在nuget中可以进行引入,如图:

在Main.axml中是这样使用的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dedede"
android:padding="10dp"
>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#00ffff"
android:id="@+id/card_view">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="科比詹姆斯JR斯密斯凯里欧文张林杜兰特库里英格拉姆格兰特希尔乔治德拉蒙德汤普森卡戴珊张林张木木易建联阿泰斯特"
android:gravity=""
android:textSize="20sp"
android:padding="10dp"
android:layout_margin="10dp"
android:textColor="#ffffff"
/>
</android.support.v7.widget.CardView>
</LinearLayout>

这是一个最普通的,设置了他的cardBackground背景色。CardView最大的亮点就是CardElelevation|:阴影和CardCornerRadius圆角,一些重要的属性如下:

  • CardView_cardBackgroundColor 设置背景色
  • CardView_cardCornerRadius 设置圆角大小
  • CardView_cardElevation 设置z轴阴影
  • CardView_cardMaxElevation 设置z轴最大高度值
  • CardView_cardUseCompatPadding 是否使用CompadPadding
  • CardView_cardPreventCornerOverlap 是否使用PreventCornerOverlap
  • CardView_contentPadding 内容的padding
  • CardView_contentPaddingLeft 内容的左padding
  • CardView_contentPaddingTop 内容的上padding
  • CardView_contentPaddingRight 内容的右padding
  • CardView_contentPaddingBottom 内容的底padding

效果图:

使用SeekBar来调整CardView样式

效果图如下:

除了在布局页添加一个SeekBar元素之外其他的地方都是一样的,在MainActivity.cs 代码如下:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V7.Widget;
using static Android.Widget.SeekBar;
namespace CardViewDemo
{
[Activity(Label = "CardViewDemo", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IOnSeekBarChangeListener
{
int count = 1;
private SeekBar seek;
private CardView cardview;
public void OnProgressChanged(SeekBar seekBar, int progress, bool fromUser)
{
if(fromUser)
{
cardview.Radius = progress;
cardview.CardElevation = progress;
}
}
public void OnStartTrackingTouch(SeekBar seekBar)
{
//throw new NotImplementedException(); 表示进度条刚开始拖动出发的操作
}
public void OnStopTrackingTouch(SeekBar seekBar)
{
//throw new NotImplementedException(); 停止拖动的时候出发的事件
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
seek = FindViewById<SeekBar>(Resource.Id.seek1);
cardview = FindViewById<CardView>(Resource.Id.card_view);
seek.SetOnSeekBarChangeListener(this); }
}
}

上面代码的逻辑相当简单,就是监听SeekBar的拖动事件,根据拖动的距离设置CardView的Radius和CardElevation。图中虽然看的不是很清楚,下面我们就来做一个ListView中应用这个CardView,当然CardView主要应用就是想ListView表格项式的显示。

Xamarin Android在ListView中应用CardView

ListView用这个CardView一起效果很好,代码很简单在ListView的Item布局中加上CardView就Ok了,代码很简单我就不贴了。盗用一张图看一下效果吧


效果看起来还不错吧。

作者:张林 原文标题:Xamarin  android CardView的使用详解

原文链接:http://blog.csdn.net/kebi007/article/details/52820102

转载随意注明出处

Xamarin android CardView的使用详解的更多相关文章

  1. xamarin Android activity生命周期详解

    学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...

  2. ANDROID L——Material Design详解(UI控件)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! Android L: Google已经确认Android L就是Android Lolli ...

  3. 《Android NFC 开发实战详解 》简介+源码+样章+勘误ING

    <Android NFC 开发实战详解>简介+源码+样章+勘误ING SkySeraph Mar. 14th  2014 Email:skyseraph00@163.com 更多精彩请直接 ...

  4. Android开发之InstanceState详解

    Android开发之InstanceState详解   本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...

  5. android bundle存放数据详解

    转载自:android bundle存放数据详解 正如大家所知道,Activity之间传递数据,是将数据存放在Intent或者Bundle中 例如: 将数据存放倒Intent中传递: 将数据放到Bun ...

  6. Cordova 打包 Android release app 过程详解

    Cordova 打包 Android release app 过程详解 时间 -- :: SegmentFault 原文 https://segmentfault.com/a/119000000517 ...

  7. Android中Service(服务)详解

    http://blog.csdn.net/ryantang03/article/details/7770939 Android中Service(服务)详解 标签: serviceandroidappl ...

  8. 给 Android 开发者的 RxJava 详解

    我从去年开始使用 RxJava ,到现在一年多了.今年加入了 Flipboard 后,看到 Flipboard 的 Android 项目也在使用 RxJava ,并且使用的场景越来越多 .而最近这几个 ...

  9. Android中mesure过程详解

    我们在编写layout的xml文件时会碰到layout_width和layout_height两个属性,对于这两个属性我们有三种选择:赋值成具体的数值,match_parent或者wrap_conte ...

随机推荐

  1. a标签嵌套解决方案

    在实际网页布局之中,我们有时候需要一整块点击区域中间还要有部分按钮点击,也就是需要a标签嵌套a标签,如下: <!-- a标签进行嵌套的时候 --><a href="#hao ...

  2. 关于事件mouseover ,mouseout ,mouseenter,mouseleave的区别

    轮播中大多会选择mouseover和mouseout  这个时候是没有任何问题的 但当遇到有css3动画的时候,会发现移入移出过快 动画还没加载完成就需要执行下一个动画,完了动画样式就错乱了. 这时候 ...

  3. 异常:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException

    这个异常是出现在注入配置文件中配置好的属性时报错的: Injection of autowired dependencies failed; nested exception is java.lang ...

  4. Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause

    Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...

  5. C#.Net与MATLAB集成

    在数学分析工具方面,MATLAB无疑是佼佼者,除了作为软件工具外,MATLAB的自定义编程语言以及混合编程的支持,使其可以与Python.R之类数学分析语言媲美.尤其是在一些传统领域的研究,由于其研究 ...

  6. C#爬虫系列(一)——国家标准全文公开系统

    网上有很多Python爬虫的帖子,不排除很多培训班借着AI的概念教Python,然后爬网页自然是其中的一个大章节,毕竟做算法分析没有大量的数据怎么成. C#相比Python可能笨重了些,但实现简单爬虫 ...

  7. python源文件转换成exe问题解决贴

    项目上做一个小工具,通过webservice接口实现配置下发.python文件调试通过了,想把它抓换成exe,网上查了下,得知有py2exe这个好用精简的小工具,本以为分分钟搞定的事情,结果经历了九转 ...

  8. (转)Python 日期和时间

    转自http://www.runoob.com/python/python-date-time.html Python 日期和时间 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见 ...

  9. LNMP1.3 一键配置环境,简单方便

    系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 需要128MB以上内存(如果为128MB的小内存VPS,Xe ...

  10. cap deploy:setup报错

    今天部署cap的时候,setup出现以下错误: 查询半天未果,不过最后还是在google找到了,可见度娘极为不靠谱! I had the same error on deploy:setup with ...