import "android.graphics.PixelFormat" import "android.content.Context" import "android.provider.Settings" import "android.animation.ObjectAnimator" import "android.animation.ArgbEvaluator" import "android.animation.ValueAnimator" import "android.view.animation.DecelerateInterpolator" import "android.graphics.Typeface" import "android.graphics.drawable.ColorDrawable" import "android.graphics.PorterDuffColorFilter" import "android.graphics.PorterDuff" function 设置宽(控件,宽度) local linearParams = 控件.getLayoutParams() linearParams.width=宽度 控件.setLayoutParams(linearParams) end function 设置高(控件,高度) local linearParams = 控件.getLayoutParams() linearParams.height=高度 控件.setLayoutParams(linearParams) end function z(sdp) import "android.util.TypedValue" dm=this.getResources().getDisplayMetrics() types={px=0,dp=1,sp=2,pt=3,["in"]=4,mm=5} n,ty=sdp:match("^(%-?[%.%d]+)(%a%a)$") return TypedValue.applyDimension(types[ty],tonumber(n),dm) end function 渐变圆角(控件,左色,右色,圆角) import "android.graphics.drawable.GradientDrawable" drawable = GradientDrawable(GradientDrawable.Orientation.TR_BL,{右色,左色}); drawable.setCornerRadii({圆角,圆角,圆角,圆角,圆角,圆角,圆角,圆角}); 控件.setBackgroundDrawable(drawable) end function kgmh(id,开事件,关事件) --画笔 local 开关状态=f local 背景画笔=Paint(); --id.BackgroundDrawable=卡片(5,0xFFFFFFFF,0xFFFFFFFF,50) 背景画笔.setColor(0xffFFFFFF) .setStrokeWidth(3) .setStyle(Paint.Style.STROKE) .setAntiAlias(true) local 背景画笔2=Paint(); 背景画笔2.setColor(0x00464648) .setAntiAlias(true) .setStrokeCap(Paint.Cap.ROUND) .setStyle(Paint.Style.FILL) .setStrokeWidth(1) local 滑块画笔=Paint(); 滑块画笔.setColor(0xFFFFFFFF) .setAntiAlias(true) .setStrokeCap(Paint.Cap.ROUND) .setStyle(Paint.Style.FILL) .setStrokeWidth(5) local 滑块画笔2=Paint(); 滑块画笔2.setColor(0xFF009BFF) .setAntiAlias(true) .setStrokeCap(Paint.Cap.ROUND) .setStyle(Paint.Style.STROKE) .setStrokeWidth(5) --绘图部分 local 宽=0 local 宽2=0 local 绘图=LuaDrawable(function(画布,画笔,mDrawable) 自绘制=mDrawable local w=mDrawable.getBounds().right local h=mDrawable.getBounds().bottom if 开关状态==true 宽=宽+3 if 宽>w*0.43 宽=w*0.43 开关状态1=true end 宽2=宽2+1.5 if 宽2>w*0.43 宽2=w*0.43 end else 宽=宽-1.5 if 宽