Shape Drawable

Android Drawable - Shape Drawable使用详解(附图) 如有问题或者疑问,可以邮件mkosto@foxmail.com 阅读详情
当你想动态的绘制一些而为图形, ShapeDrawable可能对你来说比较合适。通过一个 ShapeDrawable ,你可以通过程序绘制原始的图像和你可以想到的样式。
ShapeDrawable是Drawable的一个子类,所以你可以在使用Drawable可以使用的地方使用他。例如你可以通过setBackgroundDrawable()把他设置为一个View的背景。当然,你也可以在拥有他的自定义的View中绘制你的形状,或者添加到你的布局中。由于ShapeDrawable拥有自己的draw方法,你可以创建一个View的子类,然后在他的View.onDraw()方法中绘制ShapeDrawable。如下是一个基于View类的基本扩展,来像View类一样绘制ShapeDrawable 。
public class CustomDrawableView extends View {
      private ShapeDrawable mDrawable;

      public CustomDrawableView(Context context) {
      super(context);

      int x = 10;
      int y = 10;
      int width = 300;
      int height = 50;

      mDrawable = new ShapeDrawable(new OvalShape());
      mDrawable.getPaint().setColor(0xff74AC23);
      mDrawable.setBounds(x, y, x + width, y + height);
      }

      protected void onDraw(Canvas canvas) {
      mDrawable.draw(canvas);
      }
      }
在构造函数中,我们定义了以个OvalShape类型的ShapeDrawable.然后我们设置了这个图形的颜色和边界。如果我们不设置边界。那么这个图像不会不会被绘制,但是如果你不设置颜色,默认他会被设置为黑色。
通过已经自定义的View,你可以把他绘制到你想要的任何地方。使用上面的例子,我们可以以编程的方式在一个Activity中绘制这个图形:

     CustomDrawableView mCustomDrawableView;

      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      mCustomDrawableView = new CustomDrawableView(this);

      setContentView(mCustomDrawableView);
      }

如果你不希望从Activity而是想从一个XML布局文件中绘制这个自定义的Drawable, 这样的话 CustomDrawable 必须重置View(Context, AttributeSet) 构造方法,因为这个方法在通过XML实例话这个对象的时候将会被调用。然后,你可以 像下面这样添加一个CustomDrawable元素到XML.
   <com.example.shapedrawable.CustomDrawableView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      />

ShapeDrawable 类(像android.graphics.drawable包中的其他Drawable类型) ,允许你通过该公共的方法定义各种各样的属性。某些属性你可能希望调整,例如切换alpha值,颜色过滤器,抖动处理,透明度以及颜色。
你也可以通过XML定义原型的drawable图形。要获取更多的信息,查看 Drawable Resources中有关Shape Drawables的文档。
drawable之shape的学习 配合自己的文章drawable之shape的学习,将简单的例子上传至此,方便以后参考。 立即下载

相关推荐

Android使用shape绘制阴影图层阴影效果示例

本篇文章主要介绍了Android使用shape绘制阴影图层阴影效果示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

Drawable的使用——ShapeDrawable

ShapeDrawable在开发过程中经常用到,可以理解为通过颜色来构造的图片,可以是纯色的,也可以是渐变色的。 对应的是标签,由于这个经常用到,这里只展示个简单的效果 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" ...

那些年我们一起写的代码 686

ic后端学习笔记-floorplan

floorplan是布图规划,规划包括定义芯片的大小,定义芯片内各种模块、hard macros(硬核。比如RAM,ROM及其他IP模块等)、IO等的大小和位置,有时候还需要提前定义一些placement blockages,groups/regions等等,是后端设计的第一步,也是后续所有P&R工作的基础。floorplan与placement的区别是。

tfrofc的博客 5831

android shape java_Android Shape Drawables教程

您是否曾经想减小Android应用程序的大小或使其看起来更有趣?如果是,那么您应该尝试ShapeDrawables。首先,我们将介绍ShapeDrawables的优缺点。然后,我们将创建一些可在您的应用程序中使用的Drawables,最后,为总决赛,我们将尝试复制渐变,如Spotify应用程序/网站中所示。为什么要使用ShapeDrawables?当您想在应用程序中使用PNG或JPEG图像时,必须...

weixin_33256096的博客 316

DAIC-WOZ抑郁数据集实战:从申请到特征提取的全流程避坑指南

本文详细解析了DAIC-WOZ抑郁数据集从申请到特征提取的全流程,提供了实用的避坑指南和代码模板。涵盖数据获取技巧、多模态特征工程(面部动作单元、音频特征、文本处理)以及样本不平衡解决方案,帮助研究者高效处理这一经典抑郁分析数据集。

weixin_29196315的博客 172

Kubernetes集群资源优化实战:Volcano调度器如何帮你省下30%GPU算力

本文详细介绍了如何通过Volcano调度器的Binpack策略优化Kubernetes集群中的GPU资源利用率,解决AI模型训练中的资源碎片化问题。通过实战配置和调优指南,帮助用户提升30%的GPU算力利用率,显著降低任务等待时间和硬件成本。

weixin_30832143的博客 507

Android中ShapeDrawable资源的用法

ShapeDrawable用于定义一个基本的几何图形(如矩形、圆形、线条等),定义ShapeDrawable的XML文件的根元素是 < shape…/> 详细属性如下:solid:填充 android:color指定填充的颜色gradient:渐变 android:startColor和android:endColor分别为起始和结束颜色, android:angle是渐变角度,必须为45

俊光的专栏 3465

用VSCode远程开发Jetson小车:告别Jupyter,在本地IDE高效调试Rosmaster Python程序

本文详细介绍了如何利用VSCode的Remote-SSH扩展在本地IDE中高效开发Jetson小车的Rosmaster Python程序。通过配置远程开发环境、调试技巧和项目管理方法,开发者可以告别Jupyter Notebook的碎片化编码,实现完整的机器人控制程序开发,显著提升工作效率。

weixin_30652491的博客 477

Android Studio创建shapeDrawable的方法

一、复制drawable当中的ic_launcher_background.xml并修改名字 二、删除其余代码,并创建<shape>标签 创建<shape>标签 三、完善shape标签 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 设置透明背景色 -->

程序员猫爪 2274

高德地图JSAPI中旋转Marker点标签图片时候,且不旋转lable内容方法。

高德地图JSAPI中旋转Marker点标签图片时候,且不旋转lable内容方法

weixin_42960380的博客 2500

Win10安装Nek5000

1 安装wsl 2 2 安装Nek5000 3 安装依赖项 4 安装openmpi 5 配置Nek5000 6 编译Nek5000 7 运行Nek5000算例 8 安装paraview并查看结果

weixin_43176703的博客 3451

ShapeDrawable资源的制作与使用

Shape是xml绘图不可或缺的一部分,本文将通过一组实例来展示它的使用方法。

swt369的博客 1227

AxMath行间公式转化为office公式求和符号以及编号显示问题

AxMath行间公式转化为office公式求和符号以及编号显示问题问题描述解决方法 问题描述 首先打出axmath公式,如下: 转换后的OfficeMath公式: 字体先不说,word公式字体默认cambria math且无法编辑。比较难受的一点是求和符号与后面的 ai+bi2a_i+b_i^2ai​+bi2​比例不匹配啊!正常的比例应该是: (虽然也不太正常,将就下) 解决方法 点击变换后的office公式右侧,选择更改为"显示" 可以看到,多了一些软回车符号(⬇),如果你想删除它,不要直接选中

weixin_43543177的博客 4653

Android drawable shape

圆环嵌套圆形 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="oval"> <corners android:radius="31dp" />

嗯... 611

ABAP CDS 视图的 SAP 缓冲全解析:从 DDIC-based 到 View Entity Buffer 的最佳实践与可运行示例

本文深入探讨了SAP ABAP CDS视图中的缓冲机制,重点介绍了在DDIC-based CDS视图中使用@AbapCatalog.buffering.*注解以及在CDS View Entity中使用独立缓冲对象两种配置方式。文章首先阐述了SAP缓冲的价值,特别适用于读多写少的业务场景(如主数据访问),能够显著降低数据库负载和响应延迟。核心内容分为三部分:1)DDIC-based CDS视图中的三个关键注解(缓冲状态、缓冲类型和通用缓冲键字段数)及其使用限制;2)新一代CDS View Entity中通过独

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 187

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Drawable资源之shape drawable

用来在XML中定义shape。 文件位置: res/drawable/filename.xml 这个文件名作为资源ID使用。 编译后的资源类型:    资源指向GradientDrawable。 资源引用方式:    在Java中,R.drawable.filename    在XML中,@[package:]drawable/filename 语法: <shape

JewLeo的专栏 1311

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

android中的shape资源,Android中drawable使用Shape资源

本文实例为大家分享了drawable使用Shape资源的具体内容,供大家参考,具体内容如下1.画一条水平方向的虚线android:shape="line" >android:dashGap="3dp"android:dashWidth="6dp"android:width="1dp"android:color="#FF8C69" />Android:width=”1dp” 为线条的高度...

weixin_39611754的博客 197

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

android Shape Drawable创建两边半圆的按钮背景

android:shape="rectangle">                                                        ?xml version="1.0" encoding="utf-8"?>     xmlns:android="http://schemas.android.com/ap

ThunderRong的博客 7849

Android UI美化之Shape Drawable的使用

想美化一下程序里的EditText,发现网上关于美化的文章较少,即使有也大多是直接翻译文档,索性一边研读一边写例子。 先看一下文档对Shape Drawable的描述: Shape DrawableAn XML file that defines a geometric shape, including colors and gradients. Creates aShapeDrawabl

司光鹏的技术博客 1184

自定义drawable(shape)

自定义drawable(shape) android中可以通过shape对drawable进行自定义。   [xhtml] view plaincopy shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectang

u013053383的专栏 717

Java一行代码控制shape 优雅的解决 Drawable Shape 文件繁多问题

1. 前言我们知道开发中很多图片可以用 shape 代替,但是当项目过大,功能增多,我们会发现 Drawable 文件夹下面的 .xml 文件越来越多,比如下 我们会发现,很多文件都类似,只是颜色 大小等不一样而已,所以每次碰到用到 shape 的地方还得新建 shape .xml 。这样既麻烦并且会造成 drawable .xml文件过多。 所以我希望项目中只建立几个典型常用的 shap

guozhaohui628 3769

android drawable xml文件 之 shape

一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景。但是,也肯定也有人在能使用 Drawable 的地方选择使用一张 png 图(或者是一张 .9 图)作为 View 的背景,因为后者把问题交给 UI 设计人员去了,省事。当然,使用图片这种在项目中也很常见,如果不考虑 apk 大小,内存占用问题的话,是没...

yangxinyue315的专栏 737

android 自定义Drawable Shape 的应用

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape=["rectangle" | "oval" | "line" | "ring"] > <corners android:radius="integer" android:topLeft

似锦 1451

ProgressBar自定义旋转Drawable and shape相关属性

自定义rotate android:toDegrees值可以改变旋转的速度 <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX=...

shaoyangtangsong的专栏 398

Android Shape Drawable Resources

本文主要介绍Drawable Resources的一种,ShapeDrawable Resources的使用。其他Drawable类似 经常需要自己设置某个view的背景,比如类似新浪微博客户端微博源内容的灰底圆角效果,这个时候我们就可以使用Shape。 1、介绍 ShapeDrawable Resources是指一个XML文件,它定义了几何形状,包...

weixin_33830216的博客 137
上一篇: 从XML创建Drawables
下一篇: Nine-patch
new_abc
new_abc 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄15年 701粉丝 396原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值