Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emilsjolander/StickyScrollViewItems
A small android library for tagging views inside a ScrollView as "sticky" making them stick to the top of the scroll container until a new sticky view comes and takes it's place
https://github.com/emilsjolander/StickyScrollViewItems
Last synced: 8 days ago
JSON representation
A small android library for tagging views inside a ScrollView as "sticky" making them stick to the top of the scroll container until a new sticky view comes and takes it's place
- Host: GitHub
- URL: https://github.com/emilsjolander/StickyScrollViewItems
- Owner: emilsjolander
- License: apache-2.0
- Created: 2012-05-27T15:07:41.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-04-22T05:55:05.000Z (over 2 years ago)
- Last Synced: 2024-08-02T02:11:34.575Z (3 months ago)
- Language: Java
- Size: 346 KB
- Stars: 1,032
- Watchers: 50
- Forks: 262
- Open Issues: 54
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-android-person - StickyScrollViewItems
README
StickyScrollViewItems
=====================
StickyScrollViewItems is a `ScrollView` subclass that allowed you to mark items inside the `ScrollView` as `sticky`. The items marked as sticky will stick to the top of the `ScrollView` until another `sticky` items comes by and pushes it out of the way.Installing
----------
Add the following gradle dependency exchanging x.x.x for the latest release.
```groovy
dependencies {
compile 'se.emilsjolander:StickyScrollViewItems:x.x.x'
}
```Usage
-----
First of all replace any instance of `ScrollView` with `StickyScrollView`.
So you go from this:
```xml
```
to this:
```xml
```
As with a regular `ScrollView` you are only allowed one child. But that child can contain any number of children. It is these children or any of their children that can be tagged as a sticky view. If you want t view to stick to the top when you scroll passed it add a `sticky` tag with the `android:tag` attribute to it like this:
```xml
```
There are also two additional flags that can be set on views that were added to optimize performance for the most usual cases. If the view you want to stick either has transparency or does not have a constant representation than you must supply one or both of the following flags. `-hastransparancy` for views that have transparancy and `-nonconstant` for views that will change appearance during there sticky time (examples are buttons with pressed states as well as progress spinners).
So this ends up with 4 different ways to tag a view as sticky resulting is slightly different behaviour `android:tag="sticky"` `android:tag="sticky-hastransparancy"` `android:tag="sticky-nonconstant"` and `android:tag="sticky-hastransparancy-nonconstant"`.
If you want to add a shadow drawable below the stuck items, you must declare a namespace to find the shadow attributes `xmlns:whatever="http://schemas.android.com/apk/res-auto"`. Usually you do this in the root layout element in you layout.xml file. You can then specify the shadow drawable with `whatever:stuckShadowDrawable=""` and the shadow height with `whatever:stuckShadowHeight=""` in xml. Note that when left unspecified, the default shadow height is 10dip.
```xml
```
These shadow height and drawable can also be set programatically. Note that, unlike the xml attribute, `setShadowHeight(pixels)` only takes the values in pixels.
```java
StickyScrollView stickyScroll = (StickyScrollView) findViewById(R.id.sticky_scroll);
stickyScroll.setShadowDrawable(getResources().getDrawable(
R.drawable.shadow_drawable));
stickyScroll.setShadowHeight(50); // in pixels
```