我想在 android 中绘制类似的东西,将其用作按钮。怎么做?任何链接或建议?是贝塞尔曲线吗?
如评论中所述,您可以创建一个 PNG 并直接使用它。如果您希望侧面独立于曲线缩放,您可以对图像进行 9-patch。
根据这篇文章,您现在可以选择在 xml 中定义可绘制的路径。但仅适用于 Lollipop 及以上。
最后,您可以创建一个基本按钮并使用
编辑:
我有一点时间来创建一个
在我的实现中,我使用了渐变而不是纯色,因为它不会对实现产生影响,而且它是一个更通用的示例。
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | { private Paint paintFill; private Paint paintLine; private Paint paintClear; private Path path; private int colour; private float x0; private float y0; private float x1; private float y1; private float x2; private float y2; private float x3; private float y3; public PathView(Context context) { super(context); } public PathView(Context context, AttributeSet attrs) { super(context, attrs); } public PathView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public PathView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); initialize(); } private void initialize() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Path clipping uses hardware acceleration which is unavailable from 11 to 18 // https://stackoverflow.com/questions/8895677/work-around-canvas-clippath-that-is-not-supported-in-android-any-more setLayerType(LAYER_TYPE_SOFTWARE, null); } paintFill = new Paint(); paintFill.setAntiAlias(true); LinearGradient gradient = new LinearGradient(0, getHeight(), 0, 0, Color.WHITE, colour, Shader.TileMode.CLAMP); // Vertical gradient paintFill.setShader(gradient); paintLine = new Paint(); paintLine.setColor(colour); paintLine.setStrokeWidth(1.5f); paintLine.setStrokeCap(Paint.Cap.ROUND); paintLine.setStyle(Paint.Style.STROKE); paintLine.setAntiAlias(true); paintClear = new Paint(); paintClear.setColor(Color.WHITE); paintClear.setAntiAlias(true); } public int getColour() { return colour; } public void setColour(int colour) { this.colour = colour; initialize(); invalidate(); } public void setVars(float x1, float y1, float x2, float y2) { // When the vars changes, the path needs to be updated. // In order to make clipping easier, we draw lines from [x0, y0] to // [x0, getHeight] and [x3, y3] to [x3, getHeight]. // This makes the fill section of the path everything below the path. path = new Path(); float cx = getWidth() / 2; float cy = getHeight() / 2; this.x0 = 0; this.y0 = cy + y1; this.x1 = x1; this.y1 = cy + y1; this.x2 = x2; this.y2 = cy + y2; this.x3 = getWidth(); this.y3 = cy + y2; // Move to bottom, draw up path.moveTo(this.x0, getHeight()); path.lineTo(this.x0 - paintLine.getStrokeMiter(), this.y0); path.cubicTo(this.x1, this.y1, this.x2, this.y2, this.x3, this.y3); // Draw down path.lineTo(this.x3 + paintLine.getStrokeMiter(), getHeight()); invalidate(); } @Override public void draw(Canvas canvas) { super.draw(canvas); if (path != null && paintFill != null) { // Draw gradient background first, and then clip the irrelevant section away. // This will let our gradient be uniform irrespective of the vars used. canvas.drawRect(x0, 0, x3, getHeight(), paintFill); canvas.save(); canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(x0, 0, x3, getHeight(), paintClear); canvas.restore(); canvas.drawPath(path, paintLine); } } } |

我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些