首页 > 解决方案 > 通过单击 Recyclerview 项调用 SlidingUpPanelLayout

问题描述

我是新手并实现了一个在单击项目时androidstudio调用的函数。喜欢这个gifslidinguppanellayoutrecyclerview

这是我尝试过的:

同时,我找到了SlidingPaneLayout可能有助于解决问题的解决方案,但我无法弄清楚如何在slidinguppanellayout.

我找到的代码。来自安卓开发者

// A method on the Fragment that owns the SlidingPaneLayout,
// called by the adapter when an item is selected.

fun openDetails(itemId: Int) { 
   childFragmentManager.commit { 
      setReorderingAllowed(true)
      replace<ItemFragment>(R.id.detail_container, 
         bundleOf("itemId" to itemId)) 

// If we're already open and the detail pane is visible, 
// crossfade between the fragments. 

      if (binding.slidingPaneLayout.isOpen) { 
         setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) 
      } 
   } 
binding.slidingPaneLayout.open() 
}

我已经尝试了 2 周,但一直失败。你能告诉我当像上面的 gif 那样点击项目slidinguppanellayout时如何调用吗?recycerview

xml代码

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    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:id="@+id/main_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:gravity="bottom"
    app:umanoPanelHeight="16dp"
    app:umanoDragView="@id/main_layout">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/first_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">     

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerview"
            app:layout_constraintTop_toBottomOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_width="match_parent"
            android:layout_height="430dp"
            android:paddingBottom="15dp"
            />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/slide_layout"
        android:layout_width="match_parent"
        android:layout_height="430dp"
        android:background="#ffffff"/>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>

recyclerview adapter代码

class RecyclerViewAdapter(
        val itemList: ArrayList<CoinList>,
        val inflater: LayoutInflater
    ) : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(), Filterable {
        private var searchList: ArrayList<CoinList>? = null

        inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val name: TextView
            val count: TextView

            init {
                name = itemView.findViewById(R.id.coin_name)
                count = itemView.findViewById(R.id.coin_count)
            }
        }

        init {
            this.searchList = itemList
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val view = inflater.inflate(R.layout.item_view, parent, false)
            return ViewHolder(view)
        }

        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            holder.name.setText(itemList.get(position).name)
            holder.count.setText(itemList.get(position).count)
            holder.itemView.setOnClickListener {
            }
        }

        override fun getItemCount(): Int {
            return itemList.size
        }
}

任何帮助,将不胜感激。谢谢 :)

标签: androidandroid-studiokotlinandroid-recyclerview

解决方案


推荐阅读