一个轻量级的RecyclerView工具,让你像Javascript同样渲染Item.git
众所周知,熟练使用RecyclerView展现列表数据已是每一个Android开发者必备的能力,然而,RecyclerView仍然有它的不足, 那就是过于繁琐,相信每一个开发者都有过这样的经历,咱们为了展现一个只有单一类型的简单的列表,须要建立一个Adapter, 须要建立一个ViewHolder,而对于具备多个类型的稍微复杂的列表,咱们不但须要建立Adapter,同时还要建立多个ViewHolder..github
咱们一次又一次不断的重复着这样无聊的工做,显得那么的麻木不仁express
然而,生活不止眼前的苟且,还有诗和远方!apache
让咱们一块儿和噩梦同样的Adapter和ViewHolder说声再见,一块儿来拥抱Yaksa吧!bash
Yaksa(夜叉), 提升16点敏捷 15%攻击速度 10%移动速度app
渲染一个Linear列表:less
recycler_view.linear {
item {
HeaderItem("This is a Header")
}
itemDsl(index = 0) {
xml(R.layout.header_item)
render {
it.tv_header.text = "This is a dsl Header"
it.setOnClickListener { toast("DSL Header Clicked") }
}
}
data.forEach { each ->
itemDsl {
xml(R.layout.list_item)
render {
it.textView.text = each.title
}
}
}
}
复制代码
就是这样,没有Adapter,也没有ViewHolder,你只须要专心的渲染Item就行了!dom
效果图:工具
渲染一个Grid列表:ui
rv_list.grid {
spanCount(SPAN_COUNT)
item {
HeaderItem("This is a Header")
}
itemDsl(index = 0) {
gridSpanSize(SPAN_COUNT)
xml(R.layout.header_item)
render {
it.tv_header.text = "This is a dsl Header"
it.setOnClickListener { toast("DSL Header Clicked") }
}
}
data.forEach { each ->
itemDsl {
xml(R.layout.list_item)
render {
it.textView.text = each.title
}
renderX { position, it ->
it.setOnClickListener { toast("Clicked $position") }
}
}
}
}
复制代码
效果图:
瀑布流? 没问题:
rv_list.stagger {
spanCount(3)
item {
HeaderItem("This is a Header")
}
itemDsl(index = 0) {
staggerFullSpan(true)
xml(R.layout.header_item)
render {
it.tv_header.text = "This is a dsl Header"
it.setOnClickListener { toast("DSL Header Clicked") }
}
}
data.forEach { each ->
item {
ListItem(each.title, HEIGHTS[Random().nextInt(HEIGHTS.size)].px)
}
}
}
复制代码
效果图:
其他的Header,Footer,多种type类型更是不在话下,并且重要的是,这些都不须要你写任何的ViewHolder和Adapter
如今就开始装备夜叉吧,开启你的超神之路!
Github地址:github.com/ssseasonnn/…
Copyright 2018 Season.Zlc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
复制代码