Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Kotlin RecyclerView,底片内有多个视窗夹_Java_Android_Android Fragments_Kotlin_Android Recyclerview - Fatal编程技术网

Java Kotlin RecyclerView,底片内有多个视窗夹

Java Kotlin RecyclerView,底片内有多个视窗夹,java,android,android-fragments,kotlin,android-recyclerview,Java,Android,Android Fragments,Kotlin,Android Recyclerview,我在尝试显示包含多个ViewHolder的回收器时遇到问题,我正在测试并发送一个仅包含数据的自定义列表,以显示第一个ViewType的列表 付款.添加(购买(0,R.drawable.ic_购物车,“”,“”) payments.add(购买(0,R.drawable.ic_favorite,“,”) payments.add(购买(0,R.drawable.ic_箭头_back,“,”) 这是最底层的 class PaymentStepsFragment : SuperBottomSheetF

我在尝试显示包含多个ViewHolder的回收器时遇到问题,我正在测试并发送一个仅包含数据的自定义列表,以显示第一个ViewType的列表

付款.添加(购买(0,R.drawable.ic_购物车,“”,“”) payments.add(购买(0,R.drawable.ic_favorite,“,”) payments.add(购买(0,R.drawable.ic_箭头_back,“,”)

这是最底层的

class PaymentStepsFragment : SuperBottomSheetFragment() {

val payments = ArrayList<Any>()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    super.onCreateView(inflater, container, savedInstanceState)
    return inflater.inflate(R.layout.fragment_steps_payment, container, false)
}

private fun RecyclerAnimator(recyclerView: RecyclerView, adapter: PurchaseViewAdapter) {
    val itemAnimator = DefaultItemAnimator()
    itemAnimator.addDuration = 1000
    itemAnimator.removeDuration = 1000
    recyclerView.itemAnimator = itemAnimator
    recyclerView.adapter = adapter
    recyclerView.layoutManager = LinearLayoutManager(context)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    payments.add(Purchase(0,R.drawable.ic_cart,"",""))
    payments.add(Purchase(0,R.drawable.ic_favorite,"",""))
    payments.add(Purchase(0,R.drawable.ic_arrow_back,"",""))
    val recycler = view.findViewById<RecyclerView>(R.id.payment_rv)
    val adapter = PurchaseViewAdapter(payments, context!!)
    RecyclerAnimator(recycler, adapter)
}

override fun getCornerRadius() = context!!.resources.getDimension(R.dimen.sheet_rounded_corner)

override fun getStatusBarColor() = Color.RED
class PaymentStepsFragment:SuperBottomSheetFragment(){
val付款=阵列列表

根据要求,我添加了一个布局,我将其称为RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/view_bottom_sheet_attributes"
        tools:background="@color/colorWhite">

    <androidx.appcompat.widget.AppCompatTextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:id="@+id/text_attributes_heading"
            android:gravity="center"
            android:paddingLeft="12dp"
            android:text="TEMPORAL"
            android:textSize="18sp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

    <View
            android:layout_width="0sp"
            android:layout_height="1dp"
            android:background="@color/colorDivider"
            app:layout_constraintTop_toBottomOf="@id/text_attributes_heading"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

    <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/image_toggle"
            android:layout_marginRight="5dp"
            app:srcCompat="@drawable/ic_expand_less_black_24dp"
            app:layout_constraintTop_toTopOf="@id/text_attributes_heading"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="@id/text_attributes_heading"/>

    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:id="@+id/payment_rv"
            android:fillViewport="true"
            android:padding="5dp"
            android:clipToPadding="false"
            app:layout_constraintTop_toBottomOf="@id/text_attributes_heading"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/button_apply">

    </androidx.recyclerview.widget.RecyclerView>

    <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/colorDivider"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/payment_rv"/>

    <com.google.android.material.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:id="@+id/button_apply"
            android:layout_margin="5dp"
            android:text="@string/purchase"
            style="@style/Widget.MaterialComponents.Button"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            app:cornerRadius="0dp"
            app:layout_constraintTop_toBottomOf="@id/payment_rv"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>


另外,视图持有者的类型似乎没有达到覆盖功能…

检查布局XML它看起来
RecyclerView
视图被其他视图隐藏了
holder可能有问题。itemViewType
onBindViewHolder
中,是否在
onBindViewHolder
中设置了断点检查内部
Purchase
如果类型为OK请检查布局如果未设置
Match_Parent
height
ConstrintLayout
ConstrintLayout
RecyclerView的约束我将使用RecyclerView的布局和值持有者更新问题。ItemViewType在布局中,测试删除最后两个视图,
作为问题,谢谢!我要看看如何管理布局来处理其他组件:)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/view_bottom_sheet_attributes"
        tools:background="@color/colorWhite">

    <androidx.appcompat.widget.AppCompatTextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:id="@+id/text_attributes_heading"
            android:gravity="center"
            android:paddingLeft="12dp"
            android:text="TEMPORAL"
            android:textSize="18sp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

    <View
            android:layout_width="0sp"
            android:layout_height="1dp"
            android:background="@color/colorDivider"
            app:layout_constraintTop_toBottomOf="@id/text_attributes_heading"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

    <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/image_toggle"
            android:layout_marginRight="5dp"
            app:srcCompat="@drawable/ic_expand_less_black_24dp"
            app:layout_constraintTop_toTopOf="@id/text_attributes_heading"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="@id/text_attributes_heading"/>

    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:id="@+id/payment_rv"
            android:fillViewport="true"
            android:padding="5dp"
            android:clipToPadding="false"
            app:layout_constraintTop_toBottomOf="@id/text_attributes_heading"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/button_apply">

    </androidx.recyclerview.widget.RecyclerView>

    <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:background="@color/colorDivider"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/payment_rv"/>

    <com.google.android.material.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:id="@+id/button_apply"
            android:layout_margin="5dp"
            android:text="@string/purchase"
            style="@style/Widget.MaterialComponents.Button"
            android:insetTop="0dp"
            android:insetBottom="0dp"
            app:cornerRadius="0dp"
            app:layout_constraintTop_toBottomOf="@id/payment_rv"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>