|
| 1 | +# StickLayout [  ](https://bintray.com/wkp/maven/StickLayout/_latestVersion) |
| 2 | +粘性控件,其任意一个子控件都可滑动停留,无论是View,还是ViewGroup. |
| 3 | +## 演示图 |
| 4 | + |
| 5 | +## Gradle集成 |
| 6 | +```groovy |
| 7 | +dependencies{ |
| 8 | + compile 'com.wkp:StickLayout:1.0.1' |
| 9 | + //Android Studio3.0+可用以下方式 |
| 10 | + //implementation 'com.wkp:StickLayout:1.0.1' |
| 11 | +} |
| 12 | +``` |
| 13 | +Note:可能存在Jcenter还在审核阶段,这时会集成失败! |
| 14 | +## 使用详解 |
| 15 | +> 属性讲解 |
| 16 | +```xml |
| 17 | + <!--是否粘性停留--> |
| 18 | + <attr name="wkp_stick" format="boolean"/> |
| 19 | +``` |
| 20 | +Note:每个属性都有对应的java设置代码! |
| 21 | +> 布局 |
| 22 | +```xml |
| 23 | +<?xml version="1.0" encoding="utf-8"?> |
| 24 | +<LinearLayout |
| 25 | + xmlns:android="http://schemas.android.com/apk/res/android" |
| 26 | + xmlns:app="http://schemas.android.com/apk/res-auto" |
| 27 | + xmlns:tools="http://schemas.android.com/tools" |
| 28 | + android:layout_width="match_parent" |
| 29 | + android:layout_height="match_parent" |
| 30 | + android:orientation="vertical"> |
| 31 | + |
| 32 | + <TextView |
| 33 | + android:clickable="true" |
| 34 | + android:onClick="addView" |
| 35 | + android:gravity="center" |
| 36 | + android:padding="5dp" |
| 37 | + android:text="添加条目" |
| 38 | + android:layout_width="match_parent" |
| 39 | + android:layout_height="wrap_content"/> |
| 40 | + |
| 41 | + <com.wkp.sticklayout_lib.widget.StickLayout |
| 42 | + android:id="@+id/sl" |
| 43 | + android:layout_width="match_parent" |
| 44 | + android:layout_height="wrap_content"> |
| 45 | + |
| 46 | + <TextView |
| 47 | + android:onClick="click" |
| 48 | + android:id="@+id/tv1" |
| 49 | + android:text="第1行" |
| 50 | + android:gravity="center" |
| 51 | + android:layout_width="match_parent" |
| 52 | + android:layout_height="200dp"/> |
| 53 | + |
| 54 | + <LinearLayout |
| 55 | + app:wkp_stick="true" |
| 56 | + android:orientation="horizontal" |
| 57 | + android:layout_width="match_parent" |
| 58 | + android:layout_height="40dp"> |
| 59 | + |
| 60 | + <TextView |
| 61 | + android:background="@android:color/holo_green_light" |
| 62 | + android:text="NUM1" |
| 63 | + android:gravity="center" |
| 64 | + android:layout_weight="1" |
| 65 | + android:layout_width="0dp" |
| 66 | + android:layout_height="match_parent"/> |
| 67 | + |
| 68 | + <TextView |
| 69 | + android:background="@android:color/holo_blue_light" |
| 70 | + android:text="NUM2" |
| 71 | + android:gravity="center" |
| 72 | + android:layout_weight="1" |
| 73 | + android:layout_width="0dp" |
| 74 | + android:layout_height="match_parent"/> |
| 75 | + |
| 76 | + <TextView |
| 77 | + android:background="@android:color/holo_red_light" |
| 78 | + android:text="NUM3" |
| 79 | + android:gravity="center" |
| 80 | + android:layout_weight="1" |
| 81 | + android:layout_width="0dp" |
| 82 | + android:layout_height="match_parent"/> |
| 83 | + |
| 84 | + <TextView |
| 85 | + android:background="@android:color/holo_orange_light" |
| 86 | + android:text="NUM4" |
| 87 | + android:gravity="center" |
| 88 | + android:layout_weight="1" |
| 89 | + android:layout_width="0dp" |
| 90 | + android:layout_height="match_parent"/> |
| 91 | + |
| 92 | + </LinearLayout> |
| 93 | + |
| 94 | + <TextView |
| 95 | + android:id="@+id/tv2" |
| 96 | + android:text="第2行" |
| 97 | + android:background="@android:color/holo_blue_light" |
| 98 | + android:gravity="center" |
| 99 | + android:layout_width="match_parent" |
| 100 | + android:layout_height="200dp"/> |
| 101 | + |
| 102 | + <TextView |
| 103 | + android:id="@+id/tv3" |
| 104 | + app:wkp_stick="true" |
| 105 | + android:text="第3行" |
| 106 | + android:background="@android:color/holo_green_light" |
| 107 | + android:gravity="center" |
| 108 | + android:layout_width="match_parent" |
| 109 | + android:layout_height="200dp"/> |
| 110 | + |
| 111 | + <TextView |
| 112 | + android:id="@+id/tv4" |
| 113 | + android:text="第4行" |
| 114 | + android:gravity="center" |
| 115 | + android:layout_width="match_parent" |
| 116 | + android:layout_height="200dp"/> |
| 117 | + |
| 118 | + <TextView |
| 119 | + android:id="@+id/tv5" |
| 120 | + android:text="第5行" |
| 121 | + android:gravity="center" |
| 122 | + android:layout_width="match_parent" |
| 123 | + android:layout_height="200dp"/> |
| 124 | + |
| 125 | + <TextView |
| 126 | + android:id="@+id/tv6" |
| 127 | + android:text="第6行" |
| 128 | + android:gravity="center" |
| 129 | + android:layout_width="match_parent" |
| 130 | + android:layout_height="200dp"/> |
| 131 | + |
| 132 | + <TextView |
| 133 | + android:id="@+id/tv7" |
| 134 | + android:text="第7行" |
| 135 | + android:gravity="center" |
| 136 | + android:layout_width="match_parent" |
| 137 | + android:layout_height="200dp"/> |
| 138 | + |
| 139 | + </com.wkp.sticklayout_lib.widget.StickLayout> |
| 140 | + |
| 141 | +</LinearLayout> |
| 142 | + |
| 143 | +``` |
| 144 | +Note:ScrollView嵌套StickLayout时事件被拦截,无效果! |
| 145 | +> 代码示例 |
| 146 | +```java |
| 147 | +public class MainActivity extends AppCompatActivity { |
| 148 | + |
| 149 | + private StickLayout mSl; |
| 150 | + |
| 151 | + @Override |
| 152 | + protected void onCreate(Bundle savedInstanceState) { |
| 153 | + super.onCreate(savedInstanceState); |
| 154 | + setContentView(R.layout.activity_main); |
| 155 | + mSl = findViewById(R.id.sl); |
| 156 | +// mSl.setStickView(findViewById(R.id.tv2)); |
| 157 | +// mSl.setStickView(findViewById(R.id.tv3)); |
| 158 | + } |
| 159 | + |
| 160 | + public void addView(View view) { |
| 161 | + TextView textView = new TextView(view.getContext()); |
| 162 | + textView.setGravity(Gravity.CENTER); |
| 163 | + textView.setPadding(10,10,10,10); |
| 164 | + textView.setText("新条目"); |
| 165 | + mSl.addView(textView,0); |
| 166 | + } |
| 167 | + |
| 168 | + public void click(View view) { |
| 169 | + Toast.makeText(this, "第1行", Toast.LENGTH_SHORT).show(); |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | +Note:还有其他API请根据需要自行参考! |
| 174 | +## 寄语 |
| 175 | +控件支持直接代码创建,还有更多API请观看<a href="https://github.com/wkp111/StickLayout/blob/master/sticklayout-lib/src/main/java/com/wkp/sticklayout_lib/widget/StickLayout.java">StickLayout.java</a>内的注释说明。<br/> |
| 176 | +欢迎大家使用,感觉好用请给个Star鼓励一下,谢谢!<br/> |
| 177 | +大家如果有更好的意见或建议以及好的灵感,请邮箱作者,谢谢!<br/> |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | +## 版本更新 |
| 183 | +* v1.0.1<br/> |
| 184 | +新创建子可粘性停留控件库 |
| 185 | +## License |
| 186 | + |
| 187 | + Copyright 2017 wkp |
| 188 | + |
| 189 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 190 | + you may not use this file except in compliance with the License. |
| 191 | + You may obtain a copy of the License at |
| 192 | + |
| 193 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 194 | + |
| 195 | + Unless required by applicable law or agreed to in writing, software |
| 196 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 197 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 198 | + See the License for the specific language governing permissions and |
| 199 | + limitations under the License. |
0 commit comments