【lua教程】布局阴影边框
activity.setContentView(loadlayout{LinearLayout;
gravity="center";
orientation="vertical";
layout_width="fill";
layout_height="fill";
{
FrameLayout;
layout_height=1080*0.35;
layout_width=1920*0.35;
{
ImageView;
layout_height="fill";
layout_width="fill";
src="https://api.vvhan.com/api/bing";
layout_margin="5dp";
};
{
LinearLayout;
id="相框";
layout_height=1080*0.35;
layout_width=1920*0.35;
};
};
})
function 边框(view,宽度,阴影,颜色,阴影颜色,外圆角,内圆角)
import "android.graphics.*"
import "android.graphics.Paint$Cap"
local scale = activity.getResources().getDisplayMetrics().scaledDensity
function dp(dpValue)
return dpValue * scale + 0.5
end
$rectf=RectF()
$path1=Path()
$path2=Path()
$画布=LuaDrawable(function(画布,画笔)
rectf.set((阴影 or dp(2))+(宽度 or dp(5)),(阴影 or dp(2))+(宽度 or dp(5)),画布.width-((阴影 or dp(2))+(宽度 or dp(5))),画布.height-((阴影 or dp(2))+(宽度 or dp(5))))
path1.addRoundRect(rectf,内圆角 or dp(2.5),内圆角 or dp(2.5),Path.Direction.CW)
rectf.set((阴影 or dp(2)),(阴影 or dp(2)),画布.width-(阴影 or dp(2)),画布.height-(阴影 or dp(2)))
path2.addRoundRect(rectf,外圆角 or dp(5),外圆角 or dp(5),Path.Direction.CW)
path2.op(path1,Path.Op.DIFFERENCE)
画布.drawPath(path2,画笔)
path1.reset()
path2.reset()
end)
画布.paint
.setStrokeCap(Cap.ROUND)
.setAntiAlias(true)
.setDither(true)
.setShadowLayer(阴影 or dp(2),0,0,阴影颜色 or 0x7f000000)
.setColor(颜色 or 0xfff5f5f5)
view.background=画布
end
边框(相框)
页:
[1]