Skip to content

Commit

Permalink
Add scrollbar docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Jun 16, 2024
1 parent 0131240 commit c8c0f45
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Why should you use this library?
| Prefetching upcoming items ||||
| Reverse layout ||||
| Testing library ||||
| Scrollbars ||||
| Drag and Drop ||||
| Infinite layout with loop ||||
| Smooth alignment changes ||||
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Why should you use this library?
| Prefetching upcoming items ||||
| Reverse layout ||||
| Testing library ||||
| Scrollbars ||||
| Drag and Drop ||||
| Infinite layout with loop ||||
| Smooth alignment changes ||||
Expand Down
64 changes: 64 additions & 0 deletions docs/recipes/scrollbars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Scrollbar Recipe

Scrollbars are composed of two parts:

1. Thumb: the main indicator for the current scroll position
2. Track: the background of the scrollbar


!!! note
Unfortunately, scrollbars can only be defined in XML. You can create a style for re-usability.

## Defining scrollbar appearance

Thumb example:

```xml linenums="1"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="4dp" />
<solid android:color="@color/white" />

</shape>
```

Track example:

```xml linenums="1"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/black" />

</shape>

```

## `DpadRecyclerView` scrollbar configuration

To apply the above scrollbar appearance, place this in your `DpadRecyclerView` XML definition

```xml linenums="1" hl_lines="6-8"
<com.rubensousa.dpadrecyclerview.DpadRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="6dp"
android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
android:scrollbarTrackVertical="@drawable/scrollbar_track"
android:scrollbars="vertical" />
```

!!! note
Replace "Vertical" with "Horizontal" for horizontal scrollbars


By default, the scrollbar is only shown after scrolling and then disappears.
You can force it to always appear by using this attribute:

```xml linenums="1"
<com.rubensousa.dpadrecyclerview.DpadRecyclerView
android:scrollbarAlwaysDrawVerticalTrack="true" />
```

3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ nav:
- 'Testing': testing.md
- 'XML attributes': xml.md
- 'Recipes':
- 'Alignment': recipes/alignment.md
- 'Layout': recipes/layout.md
- 'Spacing': recipes/spacing.md
- 'Alignment': recipes/alignment.md
- 'Focus': recipes/focus.md
- 'Scrolling': recipes/scrolling.md
- 'Scrollbars': recipes/scrollbars.md
- 'Drag and drop': recipes/dragdrop.md
- 'Changelog': changelog.md
- 'API': api/

0 comments on commit c8c0f45

Please sign in to comment.