|
1 | | -# CSLayout |
2 | | - >1.一个支持所有View圆角的库 当然不仅仅是圆角 同时支持单独配置四个角圆角大小 四边阴影颜色及长度四边剪切长度 |
3 | | - |
4 | | - >2.扩展CSLayout 实现了一个共享元素的动画效果不同于Android官方的共享动画 支持圆角变换支持自定义传入参数 自定义Animator效果 |
5 | | - 关于动画部分 查看 [https://www.jianshu.com/p/001e6cd66bf9](https://www.jianshu.com/p/001e6cd66bf9) |
6 | | - |
7 | | - |
8 | | -## 使用方式 ## |
9 | | - |
10 | | -### 1 将cslibrary 添加到项目 ### |
11 | | -[](https://jitpack.io/#XueMoMo/CSLayout) |
12 | | -Add it in your root build.gradle at the end of repositories: |
13 | | - |
14 | | - allprojects { |
15 | | - repositories { |
16 | | - ... |
17 | | - maven { url 'https://jitpack.io' } |
18 | | - } |
19 | | - } |
20 | | -Step 2. Add the dependency |
21 | | - |
22 | | - dependencies { |
23 | | - implementation 'com.github.XueMoMo:CSLayout:v1.1.1' |
24 | | - } |
25 | | - |
26 | | -### 2.1 布局文件中使用 CSLayout ### |
27 | | - |
28 | | - <com.eericxu.cslibrary.CSLayout xmlns:android="http://schemas.android.com/apk/res/android" |
29 | | - xmlns:app="http://schemas.android.com/apk/res-auto" |
30 | | - android:layout_width="match_parent" |
31 | | - android:layout_height="350dp" |
32 | | - app:cs_corner_overlay="false" |
33 | | - app:cs_clip="20dp" |
34 | | - app:cs_corner="20dp" |
35 | | - app:cs_shadow_size="15dp"> |
36 | | - <ImageView |
37 | | - android:id="@+id/iv_cover" |
38 | | - android:layout_width="match_parent" |
39 | | - android:layout_height="match_parent" |
40 | | - android:scaleType="centerCrop" |
41 | | - android:src="@mipmap/img_4" /> |
42 | | - |
43 | | - |
44 | | - </com.eericxu.cslibrary.CSLayout> |
45 | | - |
46 | | -### 2.2 自定义布局使用 CSHelper ### |
47 | | - |
48 | | - val csHelper = CSHelper() |
49 | | - constructor(context: Context?) : super(context) |
50 | | - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { |
51 | | - csHelper.initAttr(this,context, attrs) |
52 | | - } |
53 | | - |
54 | | - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
55 | | - csHelper.initAttr(this,context, attrs) |
56 | | - } |
57 | | - var isDrawed = false |
58 | | - override fun draw(canvas: Canvas?) { |
59 | | - setLayerType(LAYER_TYPE_SOFTWARE,null) |
60 | | - isDrawed = true |
61 | | - csHelper.drawBefore(canvas,isInEditMode) |
62 | | - super.draw(canvas) |
63 | | - csHelper.drawAfter(canvas,isInEditMode) |
64 | | - |
65 | | - } |
66 | | - |
67 | | - override fun dispatchDraw(canvas: Canvas?) { |
68 | | - if (isDrawed) |
69 | | - super.dispatchDraw(canvas) |
70 | | - else { |
71 | | - csHelper.drawBefore(canvas,isInEditMode) |
72 | | - super.dispatchDraw(canvas) |
73 | | - csHelper.drawAfter(canvas,isInEditMode) |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - |
78 | | - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { |
79 | | - super.onSizeChanged(w, h, oldw, oldh) |
80 | | - csHelper.onSizeChange(this,w, h) |
81 | | - } |
82 | | -### 3 属性对照 ### |
83 | | - |
84 | | - <!-- *公共属性* --> |
85 | | - <!--圆形--> |
86 | | - <attr name="cs_circle" format="boolean" /> |
87 | | - <!--全部圆角半径--> |
88 | | - <attr name="cs_corner" format="integer|dimension" /> |
89 | | - <!--针对各个角的圆角半径--> |
90 | | - <attr name="cs_corner_top_left" format="integer|dimension" /> |
91 | | - <attr name="cs_corner_top_right" format="integer|dimension" /> |
92 | | - <attr name="cs_corner_bottom_left" format="integer|dimension" /> |
93 | | - <attr name="cs_corner_bottom_right" format="integer|dimension" /> |
94 | | - |
95 | | - <!-- 阴影--> |
96 | | - <attr name="cs_shadow_size" format="integer|dimension" /> //阴影长度 |
97 | | - <attr name="cs_shadow_color" format="color" /> //阴影颜色 |
98 | | - //四边阴影大小 |
99 | | - <attr name="cs_shadow_size_left" format="integer|dimension" /> |
100 | | - <attr name="cs_shadow_size_top" format="integer|dimension" /> |
101 | | - <attr name="cs_shadow_size_right" format="integer|dimension" /> |
102 | | - <attr name="cs_shadow_size_bottom" format="integer|dimension" /> |
103 | | - |
104 | | - <!--裁切大小--> |
105 | | - <attr name="cs_clip" format="integer|dimension" /> |
106 | | - //四边的裁切大小 |
107 | | - <attr name="cs_clip_left" format="integer|dimension" /> |
108 | | - <attr name="cs_clip_top" format="integer|dimension" /> |
109 | | - <attr name="cs_clip_right" format="integer|dimension" /> |
110 | | - <attr name="cs_clip_bottom" format="integer|dimension" /> |
111 | | - |
112 | | - <!--覆盖模式 or 裁切模式--> |
113 | | - <attr name="cs_corner_overlay" format="boolean" />//false 为覆盖模式 默认覆盖模式 true 裁切模式 |
114 | | - <attr name="cs_corner_overlay_color" format="color" /> //覆盖模式时 覆盖的颜色 |
115 | | - |
116 | | - |
117 | | -# 注意: # |
118 | | - |
119 | | - ## 阴影是绘制在裁切的边缘上 # |
120 | | - ## 阴影长度按最大阴影大小绘制 通过调整绘制区域控制各边的阴影长度 ## |
121 | | - 所以要设置阴影需要先设置裁切大小 |
122 | | - |
123 | | - cs_clip >= cs_shadow_size |
124 | | - cs_clip_left >= cs_shadow_size_left |
125 | | - cs_clip_top >= cs_shadow_size_top |
126 | | - cs_clip_right >= cs_shadow_size_right |
127 | | - cs_clip_bottom >= cs_shadow_size_bottom |
128 | | - |
129 | | - |
130 | | - |
131 | | -# [LICENSE](/LICENSE) # |
132 | | - |
| 1 | +# CSLayout |
| 2 | + >1.一个支持所有View圆角的库 当然不仅仅是圆角 同时支持单独配置四个角圆角大小 四边阴影颜色及长度四边剪切长度 |
| 3 | + |
| 4 | + >2.扩展CSLayout 实现了一个共享元素的动画效果不同于Android官方的共享动画 支持圆角变换支持自定义传入参数 自定义Animator效果 |
| 5 | + 关于动画部分 查看 [https://www.jianshu.com/p/001e6cd66bf9](https://www.jianshu.com/p/001e6cd66bf9) |
| 6 | + |
| 7 | + |
| 8 | +## 使用方式 ## |
| 9 | + |
| 10 | +### 1 将cslibrary 添加到项目 ### |
| 11 | +[](https://jitpack.io/#XueMoMo/CSLayout) |
| 12 | +Add it in your root build.gradle at the end of repositories: |
| 13 | + |
| 14 | + allprojects { |
| 15 | + repositories { |
| 16 | + ... |
| 17 | + maven { url 'https://jitpack.io' } |
| 18 | + } |
| 19 | + } |
| 20 | +Step 2. Add the dependency |
| 21 | + |
| 22 | + dependencies { |
| 23 | + implementation 'com.github.XueMoMo:CSLayout:v1.1.1' |
| 24 | + } |
| 25 | + |
| 26 | +### 2.1 布局文件中使用 CSLayout ### |
| 27 | + |
| 28 | + <com.eericxu.cslibrary.CSLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 29 | + xmlns:app="http://schemas.android.com/apk/res-auto" |
| 30 | + android:layout_width="match_parent" |
| 31 | + android:layout_height="350dp" |
| 32 | + app:cs_corner_overlay="false" |
| 33 | + app:cs_clip="20dp" |
| 34 | + app:cs_corner="20dp" |
| 35 | + app:cs_shadow_size="15dp"> |
| 36 | + <ImageView |
| 37 | + android:id="@+id/iv_cover" |
| 38 | + android:layout_width="match_parent" |
| 39 | + android:layout_height="match_parent" |
| 40 | + android:scaleType="centerCrop" |
| 41 | + android:src="@mipmap/img_4" /> |
| 42 | + |
| 43 | + |
| 44 | + </com.eericxu.cslibrary.CSLayout> |
| 45 | + |
| 46 | +### 2.2 自定义布局使用 CSHelper ### |
| 47 | + |
| 48 | + val csHelper = CSHelper() |
| 49 | + constructor(context: Context?) : super(context) |
| 50 | + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { |
| 51 | + csHelper.initAttr(this,context, attrs) |
| 52 | + } |
| 53 | + |
| 54 | + constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
| 55 | + csHelper.initAttr(this,context, attrs) |
| 56 | + } |
| 57 | + var isDrawed = false |
| 58 | + override fun draw(canvas: Canvas?) { |
| 59 | + setLayerType(LAYER_TYPE_SOFTWARE,null) |
| 60 | + isDrawed = true |
| 61 | + csHelper.drawBefore(canvas,isInEditMode) |
| 62 | + super.draw(canvas) |
| 63 | + csHelper.drawAfter(canvas,isInEditMode) |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + override fun dispatchDraw(canvas: Canvas?) { |
| 68 | + if (isDrawed) |
| 69 | + super.dispatchDraw(canvas) |
| 70 | + else { |
| 71 | + csHelper.drawBefore(canvas,isInEditMode) |
| 72 | + super.dispatchDraw(canvas) |
| 73 | + csHelper.drawAfter(canvas,isInEditMode) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + |
| 78 | + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { |
| 79 | + super.onSizeChanged(w, h, oldw, oldh) |
| 80 | + csHelper.onSizeChange(this,w, h) |
| 81 | + } |
| 82 | +### 3 属性对照 ### |
| 83 | + |
| 84 | + <!-- *公共属性* --> |
| 85 | + <!--圆形--> |
| 86 | + <attr name="cs_circle" format="boolean" /> |
| 87 | + <!--全部圆角半径--> |
| 88 | + <attr name="cs_corner" format="integer|dimension" /> |
| 89 | + <!--针对各个角的圆角半径--> |
| 90 | + <attr name="cs_corner_top_left" format="integer|dimension" /> |
| 91 | + <attr name="cs_corner_top_right" format="integer|dimension" /> |
| 92 | + <attr name="cs_corner_bottom_left" format="integer|dimension" /> |
| 93 | + <attr name="cs_corner_bottom_right" format="integer|dimension" /> |
| 94 | + |
| 95 | + <!-- 阴影--> |
| 96 | + <attr name="cs_shadow_size" format="integer|dimension" /> //阴影长度 |
| 97 | + <attr name="cs_shadow_color" format="color" /> //阴影颜色 |
| 98 | + //四边阴影大小 |
| 99 | + <attr name="cs_shadow_size_left" format="integer|dimension" /> |
| 100 | + <attr name="cs_shadow_size_top" format="integer|dimension" /> |
| 101 | + <attr name="cs_shadow_size_right" format="integer|dimension" /> |
| 102 | + <attr name="cs_shadow_size_bottom" format="integer|dimension" /> |
| 103 | + |
| 104 | + <!--裁切大小--> |
| 105 | + <attr name="cs_clip" format="integer|dimension" /> |
| 106 | + //四边的裁切大小 |
| 107 | + <attr name="cs_clip_left" format="integer|dimension" /> |
| 108 | + <attr name="cs_clip_top" format="integer|dimension" /> |
| 109 | + <attr name="cs_clip_right" format="integer|dimension" /> |
| 110 | + <attr name="cs_clip_bottom" format="integer|dimension" /> |
| 111 | + |
| 112 | + <!--覆盖模式 or 裁切模式--> |
| 113 | + <attr name="cs_corner_overlay" format="boolean" />//false 为覆盖模式 默认覆盖模式 true 裁切模式 |
| 114 | + <attr name="cs_corner_overlay_color" format="color" /> //覆盖模式时 覆盖的颜色 |
| 115 | + |
| 116 | + |
| 117 | +# 注意: # |
| 118 | + |
| 119 | + ## 阴影是绘制在裁切的边缘上 # |
| 120 | + ## 阴影长度按最大阴影大小绘制 通过调整绘制区域控制各边的阴影长度 ## |
| 121 | + 所以要设置阴影需要先设置裁切大小 |
| 122 | + |
| 123 | + cs_clip >= cs_shadow_size |
| 124 | + cs_clip_left >= cs_shadow_size_left |
| 125 | + cs_clip_top >= cs_shadow_size_top |
| 126 | + cs_clip_right >= cs_shadow_size_right |
| 127 | + cs_clip_bottom >= cs_shadow_size_bottom |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +# [LICENSE](/LICENSE) # |
| 132 | + |
0 commit comments