本文介绍了在画布上绘制一个闪烁的圆圈 - android studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我有java类扩展视图。我在画布上画了一个简单的圆圈。要求是使此圆圈闪烁或闪烁。我尝试了很多东西并且搜索了很多没有运气的东西。通过添加动画使textView或图像闪烁非常容易,但是我必须绘制的圆圈然后使其闪烁。 任何帮助将不胜感激 我尝试过: 这是我的圈子: mCircle = new Paint(); mCircle.setARGB( 255 , 100 , 255 , 255 ); mCircle.setShadowLayer( 100 , 0 , 0 ,Color.BLUE); canvas.drawCircle(x,y,value,mCircle); setLayerType( 1 ,mCircle); 我已经尝试了这个链接 [ ^ ]但不工作解决方案 闪烁或频闪会导致某些人癫痫发作,因此不建议使用。 它与吮吸网站分组。 (旋转是更好的IMO)。 我创建了一种方法,每X次切换两种颜色。 我在类构造函数上调用了这个方法(类扩展View ) 方法: private void setCircleAnimation(){ final int color1 = Color.parseColor( #3399ff); final int color2 = Color.parseColor( #84c1ff); circleColor = color1; postDelayed( new Runnable(){ @ Override public void run(){ circleColor =(circleColor == color1)?color2:color1; invalidate(); postDelayed( this , 300 ); } }, 300 );在构造函数上调用此函数后} 。我在问题的代码片段中画了一个圆圈。 不确定这是最好的方法,但它现在有效。 任何其他建议或非常欢迎更正。 谢谢 Hi all,I have java class extends view. I draw a simple circle on canvas. The requirements is to make this circle blink or flash. I have tried many things and searched alot with no luck. It's pretty easy to make textView or image blink by adding animation, but the circle I have to draw then make it blink.Any help will be appreciatedWhat I have tried:Here is my circle:mCircle = new Paint();mCircle.setARGB(255, 100, 255, 255);mCircle.setShadowLayer(100, 0, 0, Color.BLUE);canvas.drawCircle(x, y, value, mCircle);setLayerType(1, mCircle);I have tried what's said in this link[^] but not working 解决方案 Blinking or "strobing" can cause epileptic fits in certain individuals and is therefore not recommended.It's grouped in with "web sites that suck".("Rotating" is better IMO).I have created a method to switch between 2 colors every X time.I called this method on the class constructor (the class extends View)The method:private void setCircleAnimation(){ final int color1 = Color.parseColor("#3399ff"); final int color2 = Color.parseColor("#84c1ff"); circleColor = color1; postDelayed(new Runnable() { @Override public void run() { circleColor = (circleColor == color1) ? color2 : color1; invalidate(); postDelayed(this, 300); } }, 300); }after calling this function on the constructor. I draw the circle like in my code snippet in the question.Not sure it's the best way to do it, but it works for the moment.Any other suggestions or corrections are very welcome.Thanks 这篇关于在画布上绘制一个闪烁的圆圈 - android studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-31 16:16