请选择 进入手机版 | 继续访问电脑版

登录  | 立即注册

游客您好!登录后享受更多精彩

查看: 1374|回复: 0

[lua教程] 【lua教程】布局阴影边框

[复制链接]

444

主题

509

帖子

2051

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2051

荣誉管理论坛元老

发表于 2021-7-1 08:32:43 来自手机 | 显示全部楼层 |阅读模式 来自:
  1. activity.setContentView(loadlayout{
    ( z% d! K: V: h  T! Q
  2.   LinearLayout;, @2 n& O3 j0 t+ _# Y4 J( J
  3.   gravity="center";
    + u. L2 f" l& ]/ T6 G
  4.   orientation="vertical";) d4 g3 v3 |' L- `- w( U9 J
  5.   layout_width="fill";% T1 V2 x. j% W+ b7 y
  6.   layout_height="fill";! U/ m$ U- _! p  |, b
  7.   {
    / ]( V$ k: N; r/ x2 b5 W
  8.     FrameLayout;  k- p3 m& A) J* r
  9.     layout_height=1080*0.35;
    . ^* I# X8 t" E/ z& }/ p. z# U. W9 I
  10.     layout_width=1920*0.35;
    3 G+ }  [8 U: }! u" r% ~/ }5 l8 z
  11.     {! g  W: {1 A" b4 V6 P
  12.       ImageView;
    9 U" N# D' G3 D$ \8 Z6 M
  13.       layout_height="fill";5 S4 _% K1 c, k) E3 A) p* T
  14.       layout_width="fill";6 n$ W( f# E7 D  b- n
  15.       src="https://api.vvhan.com/api/bing";7 k6 w) w, s! w0 l. `3 t% Y( n5 j
  16.       layout_margin="5dp";3 ?3 o8 j% _0 Y! j
  17.     };( @$ t6 c/ N  ]  }. E) m$ D
  18.     {% c5 h0 ]4 A  V7 i8 }$ z* S9 l  S1 L3 T
  19.       LinearLayout;
    7 _' l4 w, s- v0 m/ i
  20.       id="相框";9 N7 M& f: o1 y$ G
  21.       layout_height=1080*0.35;' ?! d) g. ~  E
  22.       layout_width=1920*0.35;
    # U( X( v3 n- E# `5 ?; P+ H/ K
  23.     };1 `! {; @1 i5 x& G& s
  24.   };7 a1 X1 e- W- a) \* g) i
  25. })
    ! }* Q) O6 s1 |) i( o) G, r( H3 S0 A

  26. ! d5 ^: [7 g3 w0 @( I
  27. 0 f' d; N3 N( ~4 L$ M9 x! x2 l
  28. 1 G$ ~" p1 {5 U/ r% X# R( ^: c
  29. function 边框(view,宽度,阴影,颜色,阴影颜色,外圆角,内圆角)- U5 K& U0 Y7 G1 D, J5 [
  30.   import "android.graphics.*"- k+ d% S- q8 M* v; B
  31.   import "android.graphics.Paint$Cap"
    6 ]! C2 q# ]3 W5 z* g
  32.   local scale = activity.getResources().getDisplayMetrics().scaledDensity
    5 I6 [) ^) R8 D: z$ q# _5 s" F
  33.   function dp(dpValue)
    * a% t( J: ?+ A3 |1 H
  34.     return dpValue * scale + 0.5
    4 q* _3 z* P2 y7 \: o. K
  35.   end
    7 P# R( y# L( e  L# S0 o% |  F" L
  36.   $rectf=RectF()
    ; {6 k  r4 W5 _# g4 j+ Y( z
  37.   $path1=Path()
    4 {3 V; \- s, r% j2 e* Z& J# k
  38.   $path2=Path()
    ! ^) e9 N5 s: `
  39.   $画布=LuaDrawable(function(画布,画笔)
    $ P) ^$ r: u3 J5 X; i! A- a; Z
  40.     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))))
    ' w" h+ H0 E, L, u  F& n  ^# U8 x( p
  41.     path1.addRoundRect(rectf,内圆角 or dp(2.5),内圆角 or dp(2.5),Path.Direction.CW)6 I0 y6 T! N- @
  42.     rectf.set((阴影 or dp(2)),(阴影 or dp(2)),画布.width-(阴影 or dp(2)),画布.height-(阴影 or dp(2)))
    - K% b3 k2 C9 P* z7 T9 |
  43.     path2.addRoundRect(rectf,外圆角 or dp(5),外圆角 or dp(5),Path.Direction.CW)1 ]# k9 b3 e% f: I+ M" n9 @
  44.     path2.op(path1,Path.Op.DIFFERENCE)# d8 X% M# Z8 F) W$ d$ N8 ]. B/ d
  45.     画布.drawPath(path2,画笔)) y4 ^( D( n) _4 v8 B
  46.     path1.reset()# j3 F, ?# H; o8 G
  47.     path2.reset()
    % B- N& S  _7 N' m; F1 |
  48.   end)
    + I; Z5 A2 i; ]) |% ]
  49.   画布.paint
    & W) t0 R% Q9 P- K$ G
  50.   .setStrokeCap(Cap.ROUND)
    5 q  W5 B% Q- A! I. M0 f
  51.   .setAntiAlias(true)0 }. H, w5 ~7 e" @' u4 h; f4 H
  52.   .setDither(true)3 {5 z( @5 h$ N$ _$ H+ a) Q6 \- f8 P; I
  53.   .setShadowLayer(阴影 or dp(2),0,0,阴影颜色 or 0x7f000000)) Z" R: J: e/ Z' S: c
  54.   .setColor(颜色 or 0xfff5f5f5)3 W0 M) h5 j( O$ J. ]
  55.   view.background=画布, B' Q& S6 F: k
  56. end, _, a+ X# L* e/ {, A
  57. 边框(相框)8 I) k. O% n% v* D/ c6 ?
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|星空社区 |网站地图

GMT+8, 2024-3-29 15:50 , Processed in 0.052977 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表