Skip to content

Commit 9f3255b

Browse files
committed
Add indicator size and margin customization to example
1 parent 0db45a5 commit 9f3255b

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

sample-app/src/main/java/cz/intik/overflowpagerindicator/MainActivity.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,29 @@ import cz.intik.overflowindicator.SimpleSnapHelper
1717
*/
1818
class MainActivity : AppCompatActivity() {
1919

20+
data class Data(
21+
val recyclerViewId: Int,
22+
val indicatorViewId: Int,
23+
val itemCount: Int,
24+
val delay: Long
25+
)
26+
27+
private val data = listOf(
28+
Data(R.id.recyclerView, R.id.viewPagerIndicator, 20, 500L),
29+
Data(R.id.recyclerViewColors, R.id.viewPagerIndicatorColors, 9, 1_000L),
30+
Data(R.id.recyclerViewSizes, R.id.viewPagerIndicatorSizes, 5, 2_000L)
31+
)
32+
2033
override fun onCreate(savedInstanceState: Bundle?) {
2134
super.onCreate(savedInstanceState)
2235
setContentView(R.layout.activity_main)
2336

24-
initRecyclerWithIndicator(R.id.recycler_view, R.id.view_pager_indicator, 20, 1000)
25-
initRecyclerWithIndicator(
26-
R.id.recycler_view_simple, R.id.view_pager_indicator_simple, 5, 2000
27-
)
37+
data.forEach(::initRecyclerWithIndicator)
2838
}
2939

30-
private fun initRecyclerWithIndicator(
31-
recyclerViewId: Int,
32-
indicatorViewId: Int,
33-
itemCount: Int,
34-
delay: Int
35-
) {
40+
private fun initRecyclerWithIndicator(data: Data) {
41+
val (recyclerViewId, indicatorViewId, itemCount, delay) = data
42+
3643
val recyclerView = findViewById<RecyclerView>(recyclerViewId)
3744
val overflowPagerIndicator = findViewById<OverflowPagerIndicator>(indicatorViewId)
3845
val adapter = Adapter()
@@ -45,13 +52,15 @@ class MainActivity : AppCompatActivity() {
4552

4653
SimpleSnapHelper(overflowPagerIndicator).attachToRecyclerView(recyclerView)
4754

48-
recyclerView.postDelayed({ adapter.updateItemCount(itemCount) }, delay.toLong())
55+
recyclerView.postDelayed({ adapter.updateItemCount(itemCount) }, delay)
4956
}
5057

5158
private class Adapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
5259
// Some material colors for recycler view items background
5360
private val colors =
54-
arrayOf("#2196F3", "#00BCD4", "#4CAF50", "#CDDC39", "#FFC107", "#FF5722")
61+
mutableListOf("#2196F3", "#00BCD4", "#4CAF50", "#CDDC39", "#FFC107", "#FF5722")
62+
.apply { shuffle() }
63+
5564
private var itemCount = 0
5665

5766
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
android:background="@color/dot_stroke"
8-
android:orientation="vertical"
9-
tools:context=".MainActivity">
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="@color/dot_stroke"
8+
android:orientation="vertical"
9+
tools:context=".MainActivity">
1010

1111
<FrameLayout
1212
android:layout_width="match_parent"
1313
android:layout_height="wrap_content"
14-
android:layout_marginTop="64dp">
14+
android:layout_marginTop="32dp">
1515

1616
<androidx.recyclerview.widget.RecyclerView
17-
android:id="@+id/recycler_view"
17+
android:id="@+id/recyclerView"
1818
android:layout_width="match_parent"
19-
android:layout_height="120dp"/>
19+
android:layout_height="100dp" />
2020

2121
<cz.intik.overflowindicator.OverflowPagerIndicator
22-
android:id="@+id/view_pager_indicator"
22+
android:id="@+id/viewPagerIndicator"
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
25-
android:layout_gravity="center"/>
25+
android:layout_gravity="center" />
2626
</FrameLayout>
2727

2828
<FrameLayout
2929
android:layout_width="match_parent"
3030
android:layout_height="wrap_content"
31-
android:layout_marginTop="64dp">
31+
android:layout_marginTop="32dp">
3232

3333
<androidx.recyclerview.widget.RecyclerView
34-
android:id="@+id/recycler_view_simple"
34+
android:id="@+id/recyclerViewColors"
3535
android:layout_width="match_parent"
36-
android:layout_height="120dp"/>
36+
android:layout_height="100dp" />
3737

3838
<cz.intik.overflowindicator.OverflowPagerIndicator
39-
android:id="@+id/view_pager_indicator_simple"
39+
android:id="@+id/viewPagerIndicatorColors"
4040
android:layout_width="wrap_content"
4141
android:layout_height="wrap_content"
4242
android:layout_gravity="center"
4343
app:dotFillColor="@color/colorAccent"
44-
app:dotStrokeColor="#0000FF"
45-
/>
44+
app:dotStrokeColor="#0000FF" />
45+
</FrameLayout>
46+
47+
<FrameLayout
48+
android:layout_width="match_parent"
49+
android:layout_height="wrap_content"
50+
android:layout_marginTop="32dp">
51+
52+
<androidx.recyclerview.widget.RecyclerView
53+
android:id="@+id/recyclerViewSizes"
54+
android:layout_width="match_parent"
55+
android:layout_height="100dp" />
56+
57+
<cz.intik.overflowindicator.OverflowPagerIndicator
58+
android:id="@+id/viewPagerIndicatorSizes"
59+
android:layout_width="wrap_content"
60+
android:layout_height="wrap_content"
61+
android:layout_gravity="center"
62+
app:indicatorMargin="6dp"
63+
app:indicatorSize="22dp" />
4664
</FrameLayout>
4765

4866
</LinearLayout>

0 commit comments

Comments
 (0)