位置: 编程技术 - 正文

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

  • 啥叫总分类账
  • 专票要写开户行和账号
  • 结转本月发生的费用
  • 发票服务名称都有什么
  • 怎么知道购货方电话号码
  • 当月费用次月收到发票
  • 母子公司无偿划转股权印花税
  • 同一笔业务可以开多张发票吗
  • 土地出让金返还的禁止性规定
  • 公允价值变动损益属于当期损益吗
  • 已入账未抵扣退回发票
  • 营改增后甲供材如何扣除
  • 外币折算会计处理例题
  • 发票已开款项未入账有什么影响?
  • 房地产公司缴纳契税的会计分录
  • 事业单位收到增资款
  • 一般纳税人可以开1%的发票吗
  • 水利建设专项收入怎么计算
  • 劳务派遣企业的规上企业认定标准
  • 资产总计与负债和所有者权益总计不一致
  • 电子发票真伪查询
  • 专利权计入什么所得
  • 个人技术投资入什么科目
  • 计征所得税会计分录怎么做?
  • 利息支出怎么结转
  • win11资源管理器卡死
  • 总产值在报表中怎么看
  • windows11怎么显示我的电脑
  • 计算完工产品成本
  • 海月水母有性别吗
  • unet网络的优缺点
  • 企业年金如何缴纳计算方法
  • 结转损益类收入科目的余额会计分录
  • 公司投资资金
  • yolov5 anchors 中 K-means聚类
  • 实用的开源软件
  • 网易游戏二面
  • 人力资源企业税收风险
  • 平价股权转让还需要所得税吗
  • 优秀员工奖励现金是工资还是福利
  • 现金流量表的附表如何编制
  • 残疾人就业保障金
  • mongodb基本操作
  • 母公司给我们减工资
  • 非三包退车能否退款
  • 资产是指()
  • sql server 2005怎么用
  • sql server字符连接
  • 新冠捐款捐物新闻
  • 零售药店过期药品整改报告
  • 发票不按实际数量单价开 但金额一致
  • 应交税费的记账分录
  • 租地青苗补偿问题
  • 机票退票手续费可以开发票吗
  • 政府无偿划拨土地如何摊销
  • 销售做不动 应该做什么
  • 收入与支出怎么说
  • 购进生产设备的进项税额抵扣政策
  • 资本金与注册资本的关系
  • 结账前要做哪些准备工作
  • vb.net with
  • macfic
  • Ubuntu Server 13.10 安装配置图解教程
  • ubuntu开机密码不记得了
  • 基于web的学生成绩管理系统毕业论文
  • Css属性中表示字体的是
  • 关于减肥的好方法
  • nodejs 文档
  • java密码强度检验工具
  • jquery的选择器作用是选中某些元素
  • jquery.handleerror
  • nodejs获取post数据
  • Http TCP 协议
  • [android那些事] linux 下android源码编译(国内被墙方案)
  • javascript网页游戏制作教程
  • js图片轮播和点击切换
  • 税费算管理费用还是财务费用
  • 如何查询税控盘口令和密码
  • 泉州国税局网站首页
  • 网上缴公积金怎么查询
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设