位置: 编程技术 - 正文

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

  • 企业所得税税前扣除吗
  • 生产企业出口退税流程
  • 劳务税是什么 和个税的区别
  • 隔月发票退回应该如何操作
  • 小规模纳税人免税会计分录
  • 可供出售金融资产和交易性金融资产
  • 无票收入在增值税申报表的哪里填
  • 印花税应计入什么账户
  • 新成立小规模纳税人开发票如何办理
  • 可以直接申请一般纳税人吗
  • 研发支出的项目叫什么
  • 企业滞留发票的产生和处理
  • 税务注销交什么税
  • 一次性加速折旧汇算清缴调增吗
  • 出售无形资产的会计科目
  • 股东债权转资本公积利和弊
  • 金税三期个人所得税扣缴系统手机版
  • 专用发票丢失如何报销
  • 房地产企业有投资性房地产吗
  • 债务免除的税务处理
  • 事业单位转账支票管理
  • 发票和款未付可以抵扣吗
  • 金银首饰的消费税在什么环节
  • 企业所得税法的主要内容
  • 进项大于销额如何处理账务处理?
  • 外资企业股权转让如何交税
  • 转让金融商品应交增值税怎么算
  • win都是10 怎么办
  • win10系统出现蓝屏恢复
  • 酒店采购布草如何入账
  • 公司收到个人入股股金,然后又投资其他公司怎么做账
  • 变更营业执照中心怎么改
  • 差额征收是啥意思
  • 电脑卡住了按什么键回到桌面
  • 增值税纳税筹划案例最新
  • laravel debug rce
  • antd-vue-pro
  • 开票一定要对公户嘛
  • 猴子摘桃玩法
  • php str_split
  • vue好不好学
  • gpt3模型大小
  • 公司资金转到法人帐户
  • 差旅费的进项税额需要转出吗
  • 暂估入库成本结转处理低于实际成本怎么办
  • 电影院属于什么经济类型
  • 对方发票丢了能红冲重开吗
  • 股权变更如何交税
  • 暂估入库的商品能出库吗
  • 小规模纳税人低于多少免征增值税
  • 消费税的特点及纳税环节
  • 园林绿化行业的市场需求是什么
  • 小额贷款在银行需要什么条件
  • 代扣代缴公积金现金流量
  • 结转损益结转了两次咋办
  • 低值易耗品的金额
  • 小规模纳税企业在应交增值税明细科目
  • 公司购入的房子卖了,如何交增值税
  • 应收票据和应付票据的区别
  • 预期信用损失率变更属于会计估计变更吗
  • 税法规定固定资产最低折旧年限
  • mysql函数返回值类型
  • mysql从5.7升级至8.0
  • win7安装mysql8.0.17
  • xp怎么把ie浏览器放到桌面
  • win10苹果版
  • linux讲解
  • win7电脑显示器颜色不正常怎么办
  • linux系统安装驱动
  • js手机模拟器
  • 12个超实用的JQuery代码片段
  • 使用jquery实现的项目
  • easyui combobox设置值
  • [置顶]星陨计划
  • jquery滚动条滚动到指定位置
  • 仿微信语音聊天
  • 四川税收总额
  • 销售皮棉税率为多少
  • 个人所得税税收政策2023最新规定
  • 广东广州税务局电话
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设