位置: 编程技术 - 正文

Material设计非得靠Android L吗?看过来,自定View仿elevation效果!(material design设计)

编辑:rootadmin

推荐整理分享Material设计非得靠Android L吗?看过来,自定View仿elevation效果!(material design设计),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:material designation,materialand design,material design的设计原则,material design web,material设计风格,materialand design,materialand design,materialand design,内容如对您有帮助,希望把文章链接给更多的朋友!

Material设计中主要就是纸和z轴的概念,如果根据z&#;绘制出阴影效果,就基本实现了elevation效果了。

先上个效果图

代码不多,效果却不错,在此抛砖引玉,希望大家开阔思维,做出更多更好效果。

package com.zjg.smart.android.view;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.util.AttributeSet;

import android.util.Log;

import android.view.View;

import com.zjg.smart.android.utils.DimensionUtils;

import com.zjg.test.Common;

public class ShadowView extends View {

private Contextcontext = null;

private float density = 1.0f;

private int z = ;

private Paintpaint = new Paint(Paint.ANTI_ALIAS_FLAG);

private int startShadowColor = 0x;

private int endShadowColor = 0x;

public ShadowView(Context context) {

this(context,null);

// TODO自动生成的构造函数存根

}

public ShadowView(Context context, AttributeSet attrs) {

this(context, attrs, 0);

// TODO自动生成的构造函数存根

}

public ShadowView(Context context, AttributeSet attrs,int defStyle) {

super(context, attrs, defStyle);

// TODO自动生成的构造函数存根

this.context = context;

density = DimensionUtils.getDensity(context);

}

protected int getInterpolationColor(int c1,int c2, int ratio) {

ratio = ratio < 0 ? 0 : ratio;

ratio = ratio > ? : ratio;

int r1 = Color.red(c1);

int g1 = Color.green(c1);

int b1 = Color.blue(c1);

int a1 = Color.alpha(c1);

int r2 = Color.red(c2);

int g2 = Color.green(c2);

int b2 = Color.blue(c2);

int a2 = Color.alpha(c2);

int r = (r1 * ( - ratio) &#; r2 * ratio) >> 8;

int g = (g1 * ( - ratio) &#; g2 * ratio) >> 8;

int b = (b1 * ( - ratio) &#; b2 * ratio) >> 8;

int a = (a1 * ( - ratio) &#; a2 * ratio) >> 8;

return Color.argb(a, r, g, b);

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

int w = getMeasuredWidth();

Log.i(Common.LOG_TAG,"w = " &#; w);

int h = getMeasuredHeight() -z;

Log.i(Common.LOG_TAG,"h = " &#; h);

int radius = (w < h ? w : h) >> 1;

Log.i(Common.LOG_TAG,"radius = " &#; radius);

float x = radius;

Log.i(Common.LOG_TAG,"x = " &#; x);

float y = radius;

Log.i(Common.LOG_TAG,"y = " &#; y);

// radius -= z;

Log.i(Common.LOG_TAG,"radius = " &#; radius);

// 阴影

int step = /z;

for (int i =z; i > 0; i--) {

int shadowColor = getInterpolationColor(startShadowColor,

endShadowColor, step * (z - i));

paint.setColor(shadowColor);

canvas.drawCircle(x, y &#; i, radius, paint);

}

// 设定颜色

paint.setColor(0xffbac8);

canvas.drawCircle(x, y, radius, paint);

}

@Override

protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {

// TODO自动生成的方法存根

Material设计非得靠Android L吗?看过来,自定View仿elevation效果!(material design设计)

setMeasuredDimension(measureWidth(widthMeasureSpec),

measureHeight(heightMeasureSpec));

}

private int measureWidth(int measureSpec) {

int result = 0;

int specMode = MeasureSpec.getMode(measureSpec);

int specSize = MeasureSpec.getSize(measureSpec);

Log.i(Common.LOG_TAG,"wSpecMode=" &#;getModeName(specMode));

Log.i(Common.LOG_TAG,"wSpecSize=" &#; specSize);

if (specMode == MeasureSpec.EXACTLY) {

// We were toldhow big to be

result = specSize;

} else {

// Measure thetext

result = (int) ( *density);

Log.i(Common.LOG_TAG,"result=" &#; result);

if (specMode == MeasureSpec.AT_MOST) {

// RespectAT_MOST value if that was what is called for by

// measureSpec

result = result < specSize ? result : specSize;

}

}

return result;

}

private int measureHeight(int measureSpec) {

int result = 0;

int specMode = MeasureSpec.getMode(measureSpec);

int specSize = MeasureSpec.getSize(measureSpec);

Log.i(Common.LOG_TAG,"hSpecMode=" &#;getModeName(specMode));

Log.i(Common.LOG_TAG,"hSpecSize=" &#; specSize);

if (specMode == MeasureSpec.EXACTLY) {

// We were toldhow big to be

result = specSize;

} else {

// Measure thetext

result = (int) ( *density);

Log.i(Common.LOG_TAG,"result=" &#; result);

if (specMode == MeasureSpec.AT_MOST) {

// RespectAT_MOST value if that was what is called for by

// measureSpec

result = result < specSize ? result : specSize;

}

}

return result &#;z;

}

private String getModeName(int specMode) {

// TODO自动生成的方法存根

if (specMode == MeasureSpec.UNSPECIFIED) {

return"UNSPECIFIED";

} else if (specMode == MeasureSpec.EXACTLY) {

return"EXACTLY";

} else if (specMode == MeasureSpec.AT_MOST) {

return"AT_MOST";

}

return"";

}

}

<?xmlversion="1.0"encoding="utf-8"?>

<RelativeLayoutxmlns:android=" xmlns: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"

tools:context=".MyActivity">

<com.zjg.smart.android.view.ShadowView

android:layout_width="dp"

android:layout_height="dp"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_marginBottom="dp"

android:layout_marginRight="dp"/>

</RelativeLayout>

package com.zjg.test;

import android.app.Activity;

import android.os.Bundle;

public class ShadowViewTest extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_shadow_test);

}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

android获取音频绝对地址 定义如下控件和变量privateButtonbtn_pickRecord;privateTextViewtv_path;finalpublicstaticintFILE_SELECT_CODE=1;StringaudioPath;代码publicvoidpickRecord(){Intentintent=newIntent(Intent.ACTION_G

android 无法保存裁剪图片 一、问题描述android取相册或者调用摄像头拍照的图片,经过裁剪保存的时候,报错无法保存裁剪图片。(在Nexus5机器上出现)二、解决过程由于Nexus5机

常用Android开源框架 1、volley项目地址

标签: material design设计

本文链接地址:https://www.jiuchutong.com/biancheng/370915.html 转载请保留说明!

上一篇:Android 执行 gson.toJson(object) 报java.lang.StackOverflowError异常(Android 执行油猴脚本)

下一篇:android获取音频绝对地址(android获取音频信息)

  • 企业汇算清缴时允许税前扣除的工资是
  • 视同销售计税价格如何确定?
  • 基本保险包括
  • 所得税会计与财务会计比较研究
  • 开票项目与实际项目不符
  • 季度申报所得税可以研发费加计扣除
  • 小规模不报税会怎么样
  • 未开票收入下月开票怎么做分录
  • 税收的三个基本要素是
  • 跨期发票可以申报抵扣进项税额吗?
  • 劳务公司的暂估费是什么
  • 公司聚餐费用标准
  • 小规模纳税人可以转为一般纳税人吗?
  • 小规模纳税人与注册资金有关系吗
  • 不交增值税就不交企业所得税吗
  • 跨年成本发票红冲怎么做会计分录
  • 地方教育附加费是什么意思
  • 6种个人所得税违规手段,财务人再小心别跳坑!
  • 为什么增值税发票税率是1%
  • 关于保安员服务内容主要包括
  • 电子承兑怎么开户
  • 到银行开公司账户需要多少手续费
  • 分公司的款汇入总公司得出什么证明
  • 印花税资金账簿税率
  • 第一次申领发票可以增额吗?
  • 一次发放数月的高温津贴如何计算个税?
  • 冲红发票开错了怎么办
  • 中国的农业成本为什么高
  • 经营性资产和非经济资产
  • 企业减免税款的会计分录
  • autorun.exe
  • 冲回上年多提的费用会计分录
  • 企业采用备抵法核算坏账
  • php语句和php变量都是区分大小写的
  • 采购原材料凭证未到达
  • php异步请求方式
  • php中数据库怎么设计
  • 哪些收入不列入交纳党费计算基数
  • php转换器
  • element - - - - - 你不知道的loading使用方式
  • 流动比率越高越好嘛
  • Python运算符的优先级别
  • 看望职工家属可以计入福利费吗
  • 收到客户付款多久到账
  • 专用发票货物名称怎么填
  • 决算报表属于会计账簿吗
  • 汇兑应该计入什么科目
  • sqlserver2005 xml字段的读写操作
  • 职工薪酬包括哪几类
  • 兼职劳务费个税计算器
  • 金蝶财务软件怎么冲销费用
  • 小规模纳税人能开专票吗2023
  • 核定征收的一般纳税人进项税额抵扣
  • 跨年度利息收入如何调整
  • 测绘费如何入账
  • 银行存款日记账手工账填写样本
  • 在数据库master中拒绝了create table权限
  • mysql5.5中文乱码解决
  • win8换win7详细过程
  • 苹果mac与平板的区别
  • centos配置网络地址命令
  • windows 自启动
  • win8适用的pr
  • unity3d界面布局
  • javascript怎么用
  • 使用jquery插件的好处
  • promise实例方法
  • upsource使用详解
  • javascript高级程序设计pdf百度云
  • js的实现原理
  • python socketcan
  • python中的类怎样理解
  • js 表格
  • 发票事业单位有税号吗
  • 税控发票开票软件提示非征期不得抄报税?是什么意思?
  • 法国进囗红酒
  • 同比减少怎么计算出来
  • 建筑企业应如何选择适用的质量体系标准
  • 柴油增值税发票
  • 北京税务代办
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设