位置: 编程技术 - 正文

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

  • 印花税核定依据和核定比例
  • 税务登记证号是纳税人识别号吗?
  • 公司给员工租的宿舍怎么交税
  • 计提增值税及附加税费怎么算
  • 购买金税盘维护费会计分录
  • 取得研发样品收入
  • 实验室报销发票
  • 有什么法规依据法律规定
  • 法人投入投资款
  • 营改增建筑安装服务发票要求
  • 商标转让所需要的材料
  • 公司代扣代缴个人所得税如何退税
  • 怎么扣除未支付的钱
  • 投标人认证证书
  • 将自产产品用于投资
  • 行政事业单位餐标
  • 支付收购股权款如何做账
  • 银行缴纳印花税的范围
  • 药店可以开具专票吗
  • 研发费用加计扣除政策执行指引
  • 物业费纳税
  • 水电费的税收分类有哪些
  • 增值税做账做错怎么处理
  • 公司技术服务部是干嘛的
  • 计提固定资产会计科目
  • 多交的增值税怎么处理
  • 公司资金周转困难怎么办
  • win10设置变成竖排
  • 公司卖二手车的流程
  • 公司收到的应收股利需要分配利润吗
  • win11多开
  • win10关闭自动更新方法永久
  • 分红率与股息率有啥区别
  • 建房转让协议书
  • php foreach循环遍历数组
  • kali linux如何使用
  • 如何办理出口退税备案
  • 计提怎么理解
  • 不得免征和抵扣税额是什么意思
  • 不走流水开发票可以吗
  • 所得税汇算清缴退税会计分录怎么做
  • mongodb聚合函数详解
  • 个人所得税进一步改革方向
  • 自来水厂的供水井
  • access字符型数据
  • 小企业会计准则适用于哪些企业
  • 不动产租赁服务包括哪些
  • 农机合作社项目申报方案
  • 利息收入管理办法
  • 应付劳务费怎么做账
  • 价外费用中的返利是什么
  • 中小企业开发票税率是多少
  • 税种的分类方法有哪些
  • 借资本公积贷递延所得税负债是什么意思
  • 何为生产型企业
  • 发票 发票专用章
  • 个体工商户和公司的优缺点
  • 设备丢失查找
  • 银行存款日记账与银行对账单之间的核对属于
  • 什么样的原始凭证不能用
  • macos怎么切换桌面
  • win7防火墙如何添加允许
  • ami 2.17.1254bios设置图解教程
  • win7系统出现蓝屏怎么进去桌面
  • 电脑的技巧
  • centos命令行乱码
  • win8商店还能用吗
  • winxp怎样设置网络
  • os x10.12支持的机型
  • win8怎么一开机就进入桌面
  • win8metro版桌面安卓下载
  • linux的防火墙配置文件
  • windows7的注册表在哪里
  • win8 系统设置
  • glrotatef函数
  • 从零开始学什么好
  • jquery定义方法
  • androidstudio性能检测工具
  • 最简单的java设计
  • 税务局人员调动
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设