ve3344 / bindingadapter Goto Github PK
View Code? Open in Web Editor NEW❤ 一个使用ViewBinding 直接生成RecyclerView Adapter的库。
License: Other
❤ 一个使用ViewBinding 直接生成RecyclerView Adapter的库。
License: Other
看了文档上使用空布局得结合分页模块才能使用空布局,且设置数据源的方法需要传入协程上下文或viewmodel
但app里目前没有用到这两个东西,能否提供一个就是单一的List对象作为数据源?
或者是能够将空布局单独出来使用(不结合分页模块) 提供一个新的(setupLoadMoreModule)类似的方法?
如题,当我的item里有个按钮点击会进行数据删除操作同时更新recyclerview数据源,好像不是很便利去获取adapter对象
简单的adapter几行搞定
如下图所示,当itemView设置了padding或marg,或者是修改了文字大小,会导致recyclerview显示的高度出现错误,直接显示出所有的item项了
主要是想实现选中的item的文字大小和未选中的item文字大小是不一样的效果
itemView布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#252935"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvItem"
android:textColor="#50535E"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Android"/>
</LinearLayout>
recyclerview的高度设置为
wrap_content
Activity中的代码:
val list = (30..100).map { it.toString() }
val adapter =
BindingAdapter<String, RvItemPickerBinding>(RvItemPickerBinding::inflate) { position, item ->
itemBinding.tvItem.text = item
if (isWheelItemSelected) {
itemBinding.tvItem.setTextColor(Color.WHITE)
//修改字体大小也会出现计算高度错误
//itemBinding.tvItem.textSize = SizeUtils.sp2px(22f).toFloat()
} else {
itemBinding.tvItem.setTextColor("#50535E".toColorInt())
//itemBinding.tvItem.textSize = SizeUtils.sp2px(14f).toFloat()
}
}
binding.apply {
rvPicker.adapter = adapter
adapter.data.addAll(list)
adapter.notifyDataSetChanged()
val module = rvPicker.setupWheelModule()
module.apply {
offset = 1 //上下偏移多少
orientation = RecyclerWheelViewModule.VERTICAL//方向
}
module.selectedPosition = list.indexOf("70")
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.