⼩视频源码,仿抖⾳App列表滑动
⼩视频源码,抖⾳列表滑动,就是⽤了 PagerSnapHelper ,PagerSnapHelper 是Android 提供的⼀个Api,每滑动⼀个Item,其作⽤类似于ViewPage那样,直接与RecycleView相关连即可
class RecycleActivity : AppCompatActivity() {
companion object {
fun launch(context: Context) {
context.startActivity<RecycleActivity>()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_recycle)
recycle_view.layoutManager = LinearLayoutManager(this)
PagerSnapHelper().attachToRecyclerView(recycle_view)
recycle_view.adapter = MyAdapter()
}
class MyAdapter : RecyclerView.Adapter<MyViewHole>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHole {
val view =
LayoutInflater.t).inflate(R.layout.item_layout, parent, false)
return MyViewHole(view)
}
override fun getItemCount() = 30
override fun onBindViewHolder(holder: MyViewHole, position: Int) {
holder.bind(position)
}
}
class MyViewHole(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(position: Int) {
itemView.findViewById<TextView>(R.id.tv).text = "$position"
}
}
}
对应的 layout ⽂件 xml ,注意 item的 宽⾼是 全屏
<?xml version="1.0" encoding="utf-8"?>
<straint.ConstraintLayout xmlns:android="schemas.android/apk/res/android"    android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="schemas.android/apk/res-auto">
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:textSize="40sp"
android:background="@color/color_00a3f3_50"
android:padding="20dp"
android:textColor="@color/color_0d0d0d"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</android.support.v7.widget.AppCompatTextView>
<Viewjava影视app源码
android:layout_width="0dp"
android:layout_height="10dp"
android:background="@color/color_00a3f3"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</View>
</straint.ConstraintLayout>
以上就是 ⼩视频源码,仿抖⾳App 列表滑动相关代码,更多内容欢迎关注之后的⽂章

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。