Material Design全新设计系列之Pallette
2017-04-20 18:21
211 查看
RecycleView+Pallette
版权声明:本文为博主原创文章,转载请注明出处
Palette介绍
Palette用法汇总
效果图以及核心代码展示
Material Design. Thanks “Marcel Ulbrich” for creating datas.
Palette英文名——调色板、颜料,Palette从图像中提取突出的颜色,赋给App UI控件如ActionBar、Toolbar、或者其他,清新简约的App很受人们追捧。
Vibrant (有活力的)
Vibrant dark(有活力的 暗色)
Vibrant light(有活力的 亮色)
Muted (柔和的)
Muted dark(柔和的 暗色)
Muted light(柔和的 亮色)
Palette有两种初始化方法,同步和异步。各自都有两个方法:
两种同步方法:
// 最好在加载图片线程中使用
// 默认调色板大小(16).
private static final int DEFAULT_CALCULATE_NUMBER_COLORS = 16;
Palette p = Palette.generate(bitmap);
//设置调色板大小numcolor
Palette p = Palette.generate(bitmap, numcolor);
两种异步方法:
通过Palette对象获取到六个样本
swatPalette.Swatch s = p.getVibrantSwatch(); //获取到充满活力的这种色调
Palette.Swatch s = p.getDarkVibrantSwatch(); //获取充满活力的黑
Palette.Swatch s = p.getLightVibrantSwatch(); //获取充满活力的亮
Palette.Swatch s = p.getMutedSwatch(); //获取柔和的色调
Palette.Swatch s = p.getDarkMutedSwatch(); //获取柔和的黑
Palette.Swatch s = p.getLightMutedSwatch(); //获取柔和的亮
对象对应的颜色方法:
getPopulation(): 像素的数量
getHsl(): HSL颜色
getBodyTextColor(): 用于内容文本的颜色
getTitleTextColor(): 标题文本的颜色
-
在build.gralde的dependencies添加appcomat v7和palette-v7依赖,RecycleView展示瀑布流数据,所以相应的添加依赖
注意:如果是Eclipse开发,需要导入相应的jar包。
核心代码如下:
源码github :
https://github.com/CreateFutureW/PaletteRecycleView
版权声明:本文为博主原创文章,转载请注明出处
Palette介绍
Palette用法汇总
效果图以及核心代码展示
Palette介绍
A Color Pallette that includes all the colors respects AndroidMaterial Design. Thanks “Marcel Ulbrich” for creating datas.
Palette英文名——调色板、颜料,Palette从图像中提取突出的颜色,赋给App UI控件如ActionBar、Toolbar、或者其他,清新简约的App很受人们追捧。
Palette用法汇总
从图像中提取突出的颜色如下:Vibrant (有活力的)
Vibrant dark(有活力的 暗色)
Vibrant light(有活力的 亮色)
Muted (柔和的)
Muted dark(柔和的 暗色)
Muted light(柔和的 亮色)
Palette有两种初始化方法,同步和异步。各自都有两个方法:
两种同步方法:
// 最好在加载图片线程中使用
// 默认调色板大小(16).
private static final int DEFAULT_CALCULATE_NUMBER_COLORS = 16;
Palette p = Palette.generate(bitmap);
//设置调色板大小numcolor
Palette p = Palette.generate(bitmap, numcolor);
两种异步方法:
// 内部使用AsyncTask // 但是可能不是最优的方法(因为有线程的切换) // 默认调色板大小(16). Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // palette进行对UI控件的赋值 } }); // 设置调色板大小 Palette.generateAsync(bitmap, numcolor, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // palette为生成的调色板 } });
通过Palette对象获取到六个样本
swatPalette.Swatch s = p.getVibrantSwatch(); //获取到充满活力的这种色调
Palette.Swatch s = p.getDarkVibrantSwatch(); //获取充满活力的黑
Palette.Swatch s = p.getLightVibrantSwatch(); //获取充满活力的亮
Palette.Swatch s = p.getMutedSwatch(); //获取柔和的色调
Palette.Swatch s = p.getDarkMutedSwatch(); //获取柔和的黑
Palette.Swatch s = p.getLightMutedSwatch(); //获取柔和的亮
对象对应的颜色方法:
getPopulation(): 像素的数量
getHsl(): HSL颜色
getBodyTextColor(): 用于内容文本的颜色
getTitleTextColor(): 标题文本的颜色
-
效果图以及核心代码展示
一.AS开发——首先需要添加Palette的依赖:在build.gralde的dependencies添加appcomat v7和palette-v7依赖,RecycleView展示瀑布流数据,所以相应的添加依赖
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:design:23.1.0' compile 'com.android.support:appcompat-v7:21.0.+' compile 'com.android.support:palette-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+' }
注意:如果是Eclipse开发,需要导入相应的jar包。
核心代码如下:
/** * 将数据与item视图进行绑定 * * @param holder * @param position */ @Override public void onBindViewHolder(final MyRecycleViewAdapter.ViewHolder holder, int position) { //文本赋值 holder.tv.setText("我是文本" + position); ImageLoader.getInstance().displayImage(s[position], holder.imageView, new ImageLoadingListener() { //加载开始 @Override public void onLoadingStarted(String s, View view) {} //加载失败 @Override public void onLoadingFailed(String s, View view, FailReason failReason) {} //加载完成 @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { holder.imageView.setImageBitmap(bitmap); if (bitmap != null) { Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { //以获取明亮的色调为例 Palette.Swatch vibrant = palette.getVibrantSwatch(); if (vibrant != null) { // If we have a vibrant color // update the title TextView holder.tv.setBackgroundColor( vibrant.getRgb()); holder.tv.setTextColor( vibrant.getTitleTextColor()); } } }); 4000 } } @Override public void onLoadingCancelled(String s, View view) {} }); }
源码github :
https://github.com/CreateFutureW/PaletteRecycleView
相关文章推荐
- 从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(视频课程讲师:徐晓卓)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(2):设计基于WCF的服务.zip(8.29 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(7):设计基于MMC 3.0的管理工具.zip(8.70 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(9):设计基于CardSpace的身份验证系统.zip(7.98 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(1):基于.NET 3.0的系统架构.zip(8.83 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(6):为网站添加Silverlight支持.zip(6.31 MB)
- 浅谈谷歌全新设计理念Material design
- Material Design----全新的界面设计语言(一)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(8):为Vista用户设计Gadget.zip(8.67 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(5):设计基于WPF的客户端.zip(6.98 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(7):设计基于MMC 3.0的管理工具.zip(8.70 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(3):设计基于WF的工作流.zip(11.65 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(4):设计基于IIS7和AJAX的网站.zip(7.53 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(6):为网站添加Silverlight支持.zip(6.31 MB)
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(2):设计基于WCF的服务.zip(8.29 MB)
- Silverlight全新的WebGame游戏设计思想系列开工啦!
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(5):设计基于WPF的客户端.zip(6.98 MB)
- 从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(1):基于.NET 3.0的系统架构.zip(8.83 MB)
- Silverlight全新的WebGame游戏设计思想系列开工啦!
- [导入]从架构设计到系统实施——基于.NET 3.0的全新企业应用系列课程(4):设计基于IIS7和AJAX的网站.zip(7.53 MB)