Created
March 13, 2019 19:11
-
-
Save davidliu/afb5bb736d9dc52c37ae1f9b67cbfb7c to your computer and use it in GitHub Desktop.
RecyclerView in a ScrollView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<ScrollView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view1" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view2" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view3" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view4" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view5" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view6" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view7" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view8" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
<androidx.recyclerview.widget.RecyclerView | |
android:id="@+id/recycler_view9" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
</LinearLayout> | |
</ScrollView> | |
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.scrollviewrecyclerview | |
import android.os.Bundle | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.recyclerview.widget.LinearLayoutManager | |
import androidx.recyclerview.widget.RecyclerView | |
import kotlinx.android.synthetic.main.activity_main.* | |
import kotlin.random.Random | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view.adapter = Adapter(); | |
recycler_view1.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view1.adapter = Adapter(); | |
recycler_view2.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view2.adapter = Adapter(); | |
recycler_view3.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view3.adapter = Adapter(); | |
recycler_view4.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view4.adapter = Adapter(); | |
recycler_view5.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view5.adapter = Adapter(); | |
recycler_view6.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view6.adapter = Adapter(); | |
recycler_view7.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view7.adapter = Adapter(); | |
recycler_view8.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view8.adapter = Adapter(); | |
recycler_view9.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); | |
recycler_view9.adapter = Adapter(); | |
} | |
} | |
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
} | |
class Adapter : RecyclerView.Adapter<ViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val view = View(parent.context) | |
view.layoutParams = ViewGroup.LayoutParams(300, 300) | |
view.setBackgroundColor(Random.nextInt()) | |
return ViewHolder(view) | |
} | |
override fun getItemCount(): Int = 10 | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment