来绘制图像,ShapeDrawable可以设置画笔的形状。...利用ShapeDrawable在代码中画图像的步骤如下: 1. ...实例化ShapeDrawable对象,并说明绘制的形状; a) 形状可以是矩形,椭圆,线和环(例如椭圆:) myShapeDrawable = new ShapeDrawable(new...该属性用于设置ShapeDrawable的content区域的Padding。 ...ShapeDrawable的大小 注意:当是线的时候只有android:width属性意义了。
和尚我最近遇到一个小需求,程序里面有个别页面,需要动态的调整某个页面的样式,包括一键变灰等效果。 以前页面是用 shape 和 draw...
com.github.forJrking:DrawableDsl:0.0.3’ } 抛弃xml创建方式示例(其他参见demo) // infix用法用于去掉括号更加简洁,详细后面说明 image src shapeDrawable...stroke(R.color.white, 2f, 5f, 8f) } //按钮点击样式 btn.background = selectorDrawable { //默认样式 normal = shapeDrawable...corner(20f) gradient(90, R.color.F97794, R.color.C623AA2) } //点击效果 pressed = shapeDrawable...return gradientDrawable } } 把build模式转换为dsl 理论上所有的build模式都可以轻松转换为dsl写法: inline fun shapeDrawable...{ this.setImageDrawable(drawable) } //使用如下 iv2 src shapeDrawable { shape(ShapeBuilder.Shape.OVAL
com.github.forJrking:DrawableDsl:0.0.3’ } 抛弃xml创建方式示例(其他参见demo) // infix用法用于去掉括号更加简洁,详细后面说明 image src shapeDrawable...stroke(R.color.white, 2f, 5f, 8f) } //按钮点击样式 btn.background = selectorDrawable { //默认样式 normal = shapeDrawable...corner(20f) gradient(90, R.color.F97794, R.color.C623AA2) } //点击效果 pressed = shapeDrawable...{ shape(ShapeBuilder.Shape.RECTANGLE) solid("#ABE2E3") } //多了括号看起来不舒服 iv2.setImageDrawable(shapeDrawable...{ this.setImageDrawable(drawable) } //使用如下 iv2 src shapeDrawable { shape(ShapeBuilder.Shape.OVAL
LayoutDrawable (图层叠加) LevelListDrawable Drawable子类之——LevelListDrawable (等级列表图片) StateListDrawable Drawable子类之—— ShapeDrawable...ShapeDrawable(圆角) ShapeDrawable资源绘制一个特定的形状,比如矩形、椭圆等。...如果你想自己动态的绘制二位图形,那么我们就可以使用ShapeDrawable资源对象,用ShapeDrawable,我们可以绘制我们所能想象的形状。。...一个ShapeDrawable 需要一个Shape对象来管理呈现资源到UI Screen,如果没有Shape设置,那么会默认使用RectShape对象。...ShapeDrawable 被定义在一个XML文件中,以 元素起始。其内部的每一个Drawable资源内嵌在元素中 <?xml version="1.0" encoding="UTF-8"?
Shape Drawable ---- When you want to dynamically draw some two-dimensional graphics, a ShapeDrawable...With a ShapeDrawable, you can programmatically draw primitive shapes and style them in any way imaginable...Because the ShapeDrawable has its own draw() method, you can create a subclass ofView that draws the...ShapeDrawable during the View.onDraw() method....Here’s a basic extension of the View class that does just this, to draw a ShapeDrawable as a View:
android.graphics.Matrix; import android.graphics.Shader.TileMode; import android.graphics.drawable.ShapeDrawable...放大镜实现方式1 * @author chroya * */ public class ShaderView extends View{ private Bitmap bitmap; private ShapeDrawable...bmp.getHeight()*FACTOR, true), TileMode.CLAMP, TileMode.CLAMP); //圆形的drawable drawable = new ShapeDrawable...super.onDraw(canvas); canvas.drawBitmap(bitmap, 0, 0, null); drawable.draw(canvas); } } 基本原理就是使用ShapeDrawable
源码分析 public class ShaderView extends View { private final Bitmap bitmap; private final ShapeDrawable...TileMode.CLAMP, TileMode.CLAMP); // 圆形的drawable drawable = new ShapeDrawable...canvas.drawBitmap(bitmap, 0, 0, null); drawable.draw(canvas); } } 基本原理就是使用ShapeDrawable
drawable = new ShapeDrawable(circle); ShapeHolder shapeHolder = new ShapeHolder(drawable);...drawable = new ShapeDrawable(circle); ShapeHolder shapeHolder = new ShapeHolder(drawable);...)); } } ShapeHolder.java public class ShapeHolder { private float x = 0, y = 0; private ShapeDrawable...y = value; } public float getY() { return y; } public void setShape(ShapeDrawable...value) { shape = value; } public ShapeDrawable getShape() { return shape;
InsetDrawable, LayerDrawable, NinePatchDrawable, PictureDrawable, RotateDrawable, ScaleDrawable, ShapeDrawable...Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable),我们根据画图的需求...ShapeDrawable A Drawable object that draws primitive shapes....关于此请参考《ShapeDrawable》 ColorDrawable A specialized Drawable that fills the Canvas with a specified
Android里面的 StateListDrawable来实现的,它可以设置多种状态,并分别为每种状态设置相应的drawable,这个drawable有两种方式来实现:1、准备多张图片 2、准备多个 ShapeDrawable...一、准备两个ShapeDrawable 1、btn_shape.xml,正常状态下的背景图 <?xml version="1.0" encoding="utf-8"?
首先,在按下按钮时(android:state_pressed="true"),我们使用一个矩形的 ShapeDrawable,设置填充颜色为 #FF3366,并且添加了圆角效果。...然后,对于按钮的默认状态,我们使用了一个矩形的 ShapeDrawable,设置了渐变背景颜色(从 #FF6699 到 #FF3366),并且同样添加了圆角效果。
Windows.h> #include #include #include #include ShapeDrawable...delete[] imgBuf; imgBuf = nullptr; //节点 osg::Geode* geode = new osg::Geode(); osg::ref_ptrShapeDrawable...> heightShape = new osg::ShapeDrawable(heightField.get()); geode->addDrawable(heightShape); //设置纹理
intent); HanoiSetting.this.finish(); 菜单 MenuInflater 设置界面 PreferenceActivity 自定义图形 ShapeDrawable
true" android:gravity="center" android:mipMap="false" android:tileMode="disabled" /> ShapeDrawable...ShapeDrawable通过颜色构造的图形、,可以是纯色的图形,也可以是有渐变效果的图形。
颜色资源 dimen 尺寸资源 array 数组资源 style 样式资源 theme 主题资源 2、drawable资源 图片资源 StateListDrawable资源 LayerDrawable资源 ShapeDrawable...ShapeDrawable资源 简单来说,Android的ShapeDrawable让我们可以不用做图就能实现各种简单的几何图形,并能控制圆角、填充颜色、边框、内边距、半径等各种属性。...定义: ShapeDrawable的根元素是。 其中android:shape="属性有4中值可以选:line, rectangle, oval, ring。...举例: 下面分别定义了两个ShapeDrawable: shape1.xml ShapeDrawable作为背景,支持将drawable对象作为背景的所有组件都可以。其中各项属性的名称可谓见名知意,不再赘述。
25, 25}; RoundRectShape roundRectShape = new RoundRectShape(outRadius, null, null); ShapeDrawable...maskDrawable = new ShapeDrawable(); maskDrawable.setShape(roundRectShape); maskDrawable.getPaint...(Color.parseColor("#000000")); maskDrawable.getPaint().setStyle(Paint.Style.FILL); ShapeDrawable...contentDrawable = new ShapeDrawable(); contentDrawable.setShape(roundRectShape); contentDrawable.getPaint
动态创建GradientDrawable并使用 用shape标签定义的xml,最终都是转化为GradientDrawable对象,而不是ShapeDrawable, 也不是起类型对应的 OvalShape...strokeWidth, strokeColor); // 设置边框宽度和颜色 gd.setColors(colors); // 设置渐变颜色数组 总结: 请注意区分 GradientDrawable 和 ShapeDrawable
(2)ShapeDrawable ShapeDrawable默认情况下是没有宽高的概念的,但是可以如果指定了size,那么这个时候shape就有了所谓的固有宽高,但是作为view的背景时,shape还是会被拉伸或者缩小为view
layout_constraintTop_toBottomOf="@id/OptionVp" app:layout_constraintVertical_weight="1" /> Drawable使用 这里用的是ShapeDrawable...[image.png] 上图中的对联和描边金线均来自ShapeDrawable,代码如下 <shape xmlns:android="http://schemas.android.com/apk/res...{ bannerVp.setCurrentItem(1, false) } } } }) item的形状 这里也是通过ShapeDrawable...(position - 1).background = resources.getDrawable(R.drawable.circlegold) } } } 这里的形状也是通过ShapeDrawable