Created
January 20, 2018 14:05
-
-
Save 75py/3b510a511d3d3231bc409e5517207818 to your computer and use it in GitHub Desktop.
Sample (fast scroll in RecyclerView)
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"?> | |
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/recyclerView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:fastScrollEnabled="true" | |
app:fastScrollVerticalThumbDrawable="@drawable/fast_scroll_thumb2" | |
app:fastScrollVerticalTrackDrawable="@drawable/fast_scroll_track2" /> |
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"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true"> | |
<shape android:shape="rectangle"> | |
<solid android:color="#f00" /> | |
</shape> | |
</item> | |
<item> | |
<shape android:shape="rectangle"> | |
<solid android:color="#00f" /> | |
</shape> | |
</item> | |
</selector> |
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"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true"> | |
<layer-list> | |
<item android:width="8dp" android:gravity="end"> | |
<shape android:shape="rectangle"> | |
<solid android:color="#f00" /> | |
</shape> | |
</item> | |
<item android:width="48dp"> | |
<shape android:shape="rectangle"> | |
<solid android:color="@android:color/transparent" /> | |
</shape> | |
</item> | |
</layer-list> | |
</item> | |
<item> | |
<layer-list> | |
<item android:width="8dp" android:gravity="end"> | |
<shape android:shape="rectangle"> | |
<solid android:color="#00f" /> | |
</shape> | |
</item> | |
<item android:width="48dp"> | |
<shape android:shape="rectangle"> | |
<solid android:color="@android:color/transparent" /> | |
</shape> | |
</item> | |
</layer-list> | |
</item> | |
</selector> |
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"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<solid android:color="#0f0" /> | |
</shape> |
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"?> | |
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item | |
android:width="8dp" | |
android:gravity="end"> | |
<shape android:shape="rectangle"> | |
<solid android:color="#0f0" /> | |
</shape> | |
</item> | |
<item android:width="48dp"> | |
<shape android:shape="rectangle"> | |
<solid android:color="@android:color/transparent" /> | |
</shape> | |
</item> | |
</layer-list> |
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.nagopy.android.fastscrollingwithrecyclerviewsample | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import android.support.v7.widget.LinearLayoutManager | |
import android.support.v7.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.ViewGroup | |
import android.widget.TextView | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById<RecyclerView>(R.id.recyclerView).apply { | |
setHasFixedSize(true) | |
layoutManager = LinearLayoutManager(this@MainActivity) | |
adapter = Adapter() | |
} | |
} | |
class ViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) | |
class Adapter : RecyclerView.Adapter<ViewHolder>() { | |
val items = ArrayList<String>().apply { | |
for (i in 1..100) { | |
add("No.$i") | |
} | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val v = LayoutInflater.from(parent.context) | |
.inflate(android.R.layout.simple_list_item_1, parent, false) | |
as TextView | |
return ViewHolder(v) | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.textView.text = items[position] | |
} | |
override fun getItemCount(): Int { | |
return items.size | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment