位置: 编程技术 - 正文

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获取音频信息)

  • 企业流动资产周转率下降的原因
  • 工程施工与工程结算在资产负债表里
  • 税收滞纳金计入营业外支出的哪一项
  • 财务汽车折旧年限的最新规定2020
  • 车购税申报表如何作废重开
  • 机动车销售发票怎么抵扣
  • 货到票未到怎么入账
  • 公益性捐赠纳税调整案例
  • 上个月银行流水没有录这个月补录
  • 开发票时怎么修改税收分类简称?
  • 所得税费用税率规定
  • 想要避免虚开发票,你就要注意以下行为
  • 贷款利息能抵税吗现在
  • 增值税返还收入冲减进项税
  • 专用发票离线限额是什么意思
  • 固定资产合并抵扣增值税
  • 库存虚增怎么调账
  • 企业预付的固定资产折旧
  • 公司两套账怎么记账
  • 建筑成本百分比如何确定?
  • 直接收款涉及增值税吗
  • 小规模未达起征点附加税要计提吗
  • 公转私开票可以转吗
  • 未到期的商业票据是什么
  • 合伙企业收到分红需要交所得税吗
  • 没有权限使用网络资源,请与这台服务器的管理员联系
  • xshell远程连接linux命令
  • php实现微信发红包的方法
  • php的类
  • u盘安装win8系统步骤
  • 未分配利润转增股本 母公司会计分录
  • vue适配pc
  • 公司报销医疗费用公司医保里面的钱也报吗
  • 权益法转成本法为什么用账面价值
  • php设计模式六大原则
  • 无偿赠送房屋要交税吗
  • Vision Transformer 模型详解
  • 所得税减免要做账吗
  • 投资收益如何做账务处理
  • vue获取当前行
  • 使用php免费发送短信
  • php如何入门
  • 上缴税金怎么算税额
  • 企业从政府部门辞职流程
  • 配件盘点的方法
  • php页面出不来
  • 新购固定资产怎么填写申报表
  • 跨境电商小规模运营负责那些工作
  • sql有什么
  • 计提工资大于发放工资,所得税汇算要调整吗
  • 深圳税务2021
  • 减免增值税计入营业外收入明细科目
  • 生育津贴的支付期限表述不正确的是
  • 太阳能发票图片
  • 发票抬头是个人的可以报销吗
  • 事业单位之间调动难吗
  • 确认收入时,也必须确认资产或债务
  • 折扣方式销售如何确定销售额?
  • 固定资产清理的借贷方向
  • 减值损失账务处理
  • 应当设置会计机构的单位有
  • 单独设置停工损失科目
  • win10系统如何查看显卡配置
  • win10设置怎么开
  • windowsserver2008r2版本区别
  • cmos是一种什么芯片
  • explorer.exe进程出错
  • w8系统怎么删除软件
  • hda linux
  • 文件系统的类型为raw
  • 不需要远程传输的文件
  • 我的第二个姐姐用英语怎么说
  • 使用JQuery实现Ctrl+Enter提交表单的方法
  • python制作爬虫教程
  • android的中文
  • 成都税务企业号公众号
  • 南京地税局局长名单
  • 建设工程勘察设计单位可跨部门跨地区承揽勘察设计业务
  • 2020年南通居民医保缴费标准
  • 车辆过户给自己家人
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设