recyclerview linearlayoutmanager kotlin

// Step 1: Import the necessary RecyclerView and LinearLayoutManager classes
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.LinearLayoutManager

// Step 2: Create a LinearLayoutManager instance for the RecyclerView
val layoutManager = LinearLayoutManager(context)

// Step 3: Set the orientation of the LinearLayoutManager (Vertical or Horizontal)
layoutManager.orientation = LinearLayoutManager.VERTICAL // or LinearLayoutManager.HORIZONTAL

// Step 4: Optionally, set other properties of the LinearLayoutManager
layoutManager.reverseLayout = false // Set to true if you want to reverse the layout
layoutManager.stackFromEnd = false // Set to true if you want items to be laid out from the end

// Step 5: Create a RecyclerView instance and set the LinearLayoutManager
val recyclerView = RecyclerView(context)
recyclerView.layoutManager = layoutManager

// Step 6: Create an adapter for the RecyclerView (Assuming you have a custom adapter)
val adapter = YourCustomAdapter(dataList) // Replace YourCustomAdapter with your actual adapter class
recyclerView.adapter = adapter

// Step 7: Optionally, set other properties of the RecyclerView
recyclerView.setHasFixedSize(true) // Set to true if the RecyclerView size won't change

// Step 8: Add the RecyclerView to your layout (assuming you have a ViewGroup in your layout)
yourContainer.addView(recyclerView)

Replace YourCustomAdapter with the actual class name of your custom adapter, and dataList with the actual data you want to display in the RecyclerView.