国内网站模板,业之峰装饰公司装修每平米价格,个人网站设计作品图片,企业做网站公司怎么做主要实现的那种光晕效果#xff1a;中间亮#xff0c;四周逐渐变淡的。
这边有三种发光效果#xff0c;先上效果图。
第一种、圆形发光体 实现代码#xff1a;新建shape_light.xml#xff0c;导入以下代码。使用时#xff0c;直接给view设置为background。
?xml …主要实现的那种光晕效果中间亮四周逐渐变淡的。
这边有三种发光效果先上效果图。
第一种、圆形发光体 实现代码新建shape_light.xml导入以下代码。使用时直接给view设置为background。
?xml version1.0 encodingutf-8?
shape xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:shapeovalgradientandroid:centerColorcolor/transparentandroid:centerX0.5android:centerY0.5android:gradientRadius180dpandroid:startColorcolor/yellowandroid:typeradial /
/shape
第二种、矩形发光体 代码实现通过自定义view实现。
package com.fht.testprojectimport android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View/*** author fenghaitao* time 2023/11/1 16:40*/
class RectLightView JvmOverloads constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int 0
) : View(context, attributeSet, defStyleAttr) {private val paint: Paint Paint()private val corner 50fprivate val count 200init {paint.isAntiAlias falsepaint.style Paint.Style.FILLpaint.color Color.YELLOW}SuppressLint(DrawAllocation)override fun onDraw(canvas: Canvas?) {super.onDraw(canvas)val w width / countval h height / countfor (i in 0..count) {paint.alpha (255 / count) * iif (((width - 2 * (w * i)) 0) ((height - 2 * (h * i)) 0)) {val rectF RectF().apply {left (w * i).toFloat()top (h * i).toFloat()right (width - w * i).toFloat()bottom (height - h * i).toFloat()}canvas?.drawRoundRect(rectF, corner, corner, paint)}}}
}
第三种、矩形发光体比上一种更透明 这种有点瑕疵中间有一点空白不过稍微修改一下代码也可以去掉这里就不做修改了。
代码实现通过自定义view实现。
package com.fht.testprojectimport android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View/*** author fenghaitao* time 2023/11/1 16:40*/
class LightView JvmOverloads constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int 0
) : View(context, attributeSet, defStyleAttr) {private val paint: Paint Paint()private val corner 1fprivate val count 100init {paint.isAntiAlias falsepaint.style Paint.Style.STROKEpaint.color Color.YELLOW}SuppressLint(DrawAllocation)override fun onDraw(canvas: Canvas?) {super.onDraw(canvas)val w width / countval h height / countpaint.strokeWidth w.toFloat()for (i in 0..count) {paint.alpha (255 / count) * iif (((width - 2 * (w * i)) 0) ((height - 2 * (w * i)) 0)) {val rectF RectF().apply {left (w * i).toFloat()top (w * i).toFloat()right (width - w * i).toFloat()bottom (height - w * i).toFloat()}canvas?.drawRect(rectF, paint)}}}
}