简体   繁体   English

为什么使用KOTLIN在LinearLayoutManager RecyclerView中选择Orientation会出现这个错误

[英]Why does this error occur when choosing Orientation in LinearLayoutManager RecyclerView with KOTLIN

On Fragment file:

override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        recycle_home.layoutManager = LinearLayoutManager( this.context , LinearLayout.VERTICAL ,false )
        recycle_home.adapter = adapter_home()

    }

enter image description here在此处输入图像描述

 override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState)

        recycle_home.layoutManager = LinearLayoutManager( this.context)
        recycle_home.adapter = adapter_home()

    }

Or或者

       override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState)

            recycle_home.layoutManager = LinearLayoutManager( this.context,RecyclerView.VERTICAL,false)
            recycle_home.adapter = adapter_home()

        }

If you are trying to add layout manager to RecyclerView you can add it inside xml itself如果您尝试将布局管理器添加到 RecyclerView,您可以将其添加到 xml 本身

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/emailsRV"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:adapter="@{adapter}"
        android:layoutAnimation="@anim/layout_animation_from_bottom"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintBottom_toTopOf="@id/addNewACB"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:listitem="@layout/item_phone" />

Then if you want to add orientation you can add it in fragment or you can even create a BindingAdapter for the same然后,如果你想添加方向,你可以将它添加到片段中,或者你甚至可以为相同的创建一个 BindingAdapter

Below is the code for fragment/activity下面是片段/活动的代码

recycle_home.addItemDecoration(DividerItemDecoration(context, LinearLayoutManager.VERTICAL))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM