Skip to content

Commit

Permalink
版本0.9.8,支持多悬浮
Browse files Browse the repository at this point in the history
  • Loading branch information
weimingjue committed Feb 20, 2021
1 parent c341b57 commit 06cbe24
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 85 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## 使用方式:
基于NestedScrollView所以只允许有一个child:

然后加上android:tag="sticky"即可实现悬浮(任意child均可,只支持单悬浮
然后加上android:tag="sticky"即可实现悬浮(任意child均可,支持多个tag悬浮
```
<com.wang.sticky.StickyNestedScrollLayout
android:layout_width="match_parent"
Expand All @@ -24,6 +24,15 @@
android:layout_height="wrap_content"
android:orientation="vertical">
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:tag="sticky"
android:text="悬浮1"
android:textSize="30sp" />
...
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand All @@ -33,7 +42,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:tag="sticky"
android:text="悬浮"
android:text="悬浮2"
android:textSize="30sp" />
</FrameLayout>
...
Expand All @@ -54,20 +63,20 @@
```
StickyNestedScrollLayout.setChildTag(tv,"sticky");
```
也可以设置悬浮监听、获得悬浮距离、设置scroll监听等NestedScrollView的操作:
也可以设置悬浮监听、获得悬浮距离、修改悬浮背景、设置scroll监听等NestedScrollView的操作:
```
StickyNestedScrollLayout.setOnStickyScrollChangedListener();
StickyNestedScrollLayout.getStickyTop();
StickyNestedScrollLayout.getStickyParent();
StickyNestedScrollLayout.getScrollView();
```

### 相关问题:
首先说一下悬浮原理:当滑到顶端时,将要悬浮的view remove掉然后添加到顶部

背景色:请自己再设置一下或StickyNestedScrollLayout.getStickyParent()

背景色:请自己再设置一下

左右空白:还是背景色问题,你的悬浮view请保持和StickyNestedScrollLayout一样宽(如有需要忽略左右margin,可以提issues)
左右空白:如想忽略左右margin,可以自行套一层FrameLayout

## 导入方式
你的build.gradle要有jitpack.io,大致如下:
Expand All @@ -82,7 +91,7 @@ allprojects {
}
```
然后:
`implementation(或api) 'com.github.weimingjue:sticky:0.9.5'`
`implementation(或api) 'com.github.weimingjue:sticky:0.9.8'`

## 说明
如果没有tag="sticky"则它就是一个可嵌套滑动的view
Expand Down
31 changes: 28 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,47 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1\n2\n3\n4\n5\n6\n7\n8\n9"
android:text="1\n2"
android:textSize="80sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3\n4"
android:textSize="80sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:tag="sticky"
android:text="悬浮1"
android:textSize="30sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5\n6"
android:textSize="80sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7\n8\n9"
android:textSize="80sp" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="50dp"
android:tag="sticky"
android:text="悬浮"
android:text="悬浮2"
android:textSize="30sp" />
</FrameLayout>

Expand Down
Loading

0 comments on commit 06cbe24

Please sign in to comment.