效果:

圆形头像在我们的日常使用的app中很常见,因为圆形的头像比较美观.

使用圆形图片的方法可能有我们直接将图片裁剪成圆形再在app中使用,

还有就是使用自定义View对我们设置的任何图片自动裁剪成圆形。

这里使用github上CircleImageView

github:https://github.com/hdodenhof/CircleImageView

CardView顾名思义卡片式的View,

CardView继承的是FrameLayout,所以摆放内部控件的时候需要注意一下

可以设置阴影,圆角,等等

这里的CircleImageView还可以为头像设置描边。

我们新建一个项目,选择Navigation Drawer  Activity自动生成初始布局。

修改nav_header_main,添加圆角头像

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"> <de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/darth_vader"
app:civ_border_width="2dp"
/> </LinearLayout>

再修改content_main,添加RecyclerView,记得导包

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.xw.design2.MainActivity"
tools:showIn="@layout/app_bar_main"> <android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</RelativeLayout>

添加item布局,CardView,记得导包

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:contentPadding="10dp"
card_view:cardBackgroundColor="#303069"
card_view:cardCornerRadius="10dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
xmlns:android="http://schemas.android.com/apk/res/android"> <TextView
android:id="@+id/tv"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> </android.support.v7.widget.CardView>

接下来在MainActivity添加代码,使用我们的CardView

1. 添加成员变量和数据源

 private RecyclerView mRecyclerView;

    private String[] data={"2014 年,随着 Google 推出了全新的设计语言 Material Design,还迎来了新的 Android 支持库 v7,其中就包含了 Material Design 设计语言中关于 Card 卡片概念的实现 —— CardView。"
,"经历了相当长的一段时间相信许多 Android 开发者都已经应用了这个控件,现在才写这篇文章可能有点晚,但对于刚刚开始使用的开发者以及其他已经使用了一段时间但做出来效果不好的同学应该能帮上点小忙。"
,"Google 在 Android Lollipop 中引入了 Material Design 设计中的阴影(Elevation)和 Z 轴位移,其目的就是突出界面中不同元素之间的层次关系"
,"明年夏天,自由球员布雷克-格里芬可能重返俄克拉何马城与拉塞尔-威斯布鲁克联手。如果实现,雷霆队能真正意义上地威胁勇士队吗?"};

2.创建ViewHolder

 class MyHolder extends RecyclerView.ViewHolder{
private TextView mTextView;
public MyHolder(View itemView) {
super(itemView);
mTextView= (TextView) itemView.findViewById(R.id.tv);
}
}

3.创建Adapter

 class MyAdapter extends  RecyclerView.Adapter<MyHolder>{

        @Override
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater=LayoutInflater.from(getApplicationContext());
View v=layoutInflater.inflate(R.layout.item,parent,false);
MyHolder holder=new MyHolder(v);
return holder;
} @Override
public void onBindViewHolder(MyHolder holder, int position) {
holder.mTextView.setText(data[position]);
} @Override
public int getItemCount() {
return data.length;
}
}

4.oncreate()方法里设置Adapter

 mRecyclerView= (RecyclerView) findViewById(R.id.rv);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(new MyAdapter());

圆形头像CircleImageView和Cardview使用的更多相关文章

  1. 自定义圆形头像CircleImageView的使用和源码分析

    http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0806/3268.html tools:context="com.ex ...

  2. 【Android开源项目分析】自定义圆形头像CircleImageView的使用和源码分析

    原文地址: http://blog.csdn.net/zhoubin1992/article/details/47258639 效果

  3. Android 自定义圆形图片 CircleImageView

    1.效果预览 1.1.布局中写自定义圆形图片的路径即可 1.2.然后看一看图片效果 1.3.原图是这样的 @mipmap/ic_launcher 2.使用过程 2.1.CircleImageView源 ...

  4. 自定义控件--CircleImageView(类似于QQ、微信圆形头像自定义控件)

    现在基本上所有的需要用户注册的APP都有一个需要用户上传头像的需求,上传的头像基本都是类似于QQ.微信等社交应用圆形头像.最近,正在做的一个社交应用多处需要用到这种圆形头像的处理,总不能每次都对图片做 ...

  5. Android 圆形头像 自己动手

    圆形头像DIY 现在大部分app使用的都是圆形头像,网上开源的也很多,但是有没有考虑过DIY圆形头像呢?下面就自己实现一个,先看下demo展示 第一步:原理解释(图片很丑,原理很真) 1.画外框圆形, ...

  6. Android自定义控件实例,圆形头像(图库 + 裁剪+设置),上传头像显示为圆形,附源码

    Android项目开发中经常会遇见需要实现圆角或者圆形的图片功能,如果仅仅使用系统自带的ImageView控件显然无法实现此功能,所以通过系列文章的形式由简到繁全方位的介绍一下此功能的实现,巩固一下自 ...

  7. css3圆形头像(当图片宽高不相等时)

    1.图片宽高相等,width:300px: height:300px; 把他变成宽高100px的圆形头像 img{width:100px; height:100px; border-radius:50 ...

  8. Android之圆形头像裁切

    PS:今天项目测试组发现,百度地图定位的数据坐标位置是正确的,但是显示的数据是错误的.最后查来查去发现,那个商厦在百度地图上根本就没有那条数据,这让我如何显示,当初就推崇使用高德地图定位,上面的数据量 ...

  9. Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像

    此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...

随机推荐

  1. PostgreSQL Replication之第六章 监控您的设置(3)

    6.3 检查操作系统进程 一旦我们检查了归档以及我们的系统视图,我们就准备检查系统 进程.检查系统进程可能看起来有点粗糙,但它被证明非常有效. 在master上,我们可以简单地检查一个名为wal_se ...

  2. Bayes++ Library入门学习之熟悉class-Importance_resampler

    接下来,需要介绍的是重要性重采样类Bayesian_filter::Improtance_resampler.该类实现了两种重采样方法[1][2],和其子类的继承关系图如下: 其中Standard_r ...

  3. RMAN备份脚本--DataGuard primary

    单机环境全备   export ORACLE_BASE=/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACL ...

  4. sql sever 创建临时表的两种方法

    创建临时表       方法一:     create table #临时表名( 字段1 约束条件,             字段2 约束条件,                  .....)     ...

  5. [笔记-图论]Floyd

    用于可带负权的多源最短路 时间复杂度O(n^3) 注意一定不要给Floyd一个带负环的图,不然就没有什么意义了(最短路不存在) 模板 // Floyd // to get minumum distan ...

  6. 【Appium】每次启动是提示安装setting和unlock app的解决办法

    进入appium安装目录,C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android,编辑android.js文件,注释 ...

  7. Unity C# 设计模式(四)抽象工厂模式

    定义: 提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 工厂方法模式针对的是一个产品等级结构:而抽象工厂模式针对的是多个产品等级结构. 抽象工厂模式使用同一个 工厂等级结构负责这 ...

  8. 《R实战》读书笔记二

    第一章 R简单介绍 本章概要 1安装R 2理解R语言 3执行R程序 本章所介绍的内容概括例如以下. 一个典型的数据分析步骤如图1所看到的. 图1:典型数据分析步骤 简而言之,现今的数据分析要求我们从多 ...

  9. MongoDB 基本使用

    数据库基本操作 连接到mongoDBserver  1 ./bin/mongo 127.0.0.1:12345  查看当前数据库 1 2 3 > show dbs admin  (empty) ...

  10. vue29-vue2.0组件通信_recv

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...