-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
teach
committed
Sep 11, 2020
1 parent
ffbbd69
commit 89f60f6
Showing
8 changed files
with
359 additions
and
34 deletions.
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/donkingliang/consecutivescrollerdemo/SinkStickyActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.donkingliang.consecutivescrollerdemo; | ||
|
||
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.View; | ||
import android.widget.FrameLayout; | ||
|
||
import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout; | ||
import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter; | ||
|
||
public class SinkStickyActivity extends AppCompatActivity { | ||
|
||
private ConsecutiveScrollerLayout scrollerLayout; | ||
private FrameLayout flSink; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_sink_sticky); | ||
|
||
scrollerLayout = findViewById(R.id.scrollerLayout); | ||
|
||
flSink = findViewById(R.id.fl_sink); | ||
|
||
RecyclerView recyclerView1 = findViewById(R.id.recyclerView1); | ||
recyclerView1.setLayoutManager(new LinearLayoutManager(this)); | ||
RecyclerViewAdapter adapter1 = new RecyclerViewAdapter(this,"RecyclerView1-"); | ||
recyclerView1.setAdapter(adapter1); | ||
|
||
RecyclerView recyclerView2 = findViewById(R.id.recyclerView2); | ||
recyclerView2.setLayoutManager(new LinearLayoutManager(this)); | ||
RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-"); | ||
recyclerView2.setAdapter(adapter2); | ||
|
||
// 监听滑动 | ||
scrollerLayout.setOnVerticalScrollChangeListener(new ConsecutiveScrollerLayout.OnScrollChangeListener() { | ||
@Override | ||
public void onScrollChange(View v, int scrollY, int oldScrollY, int scrollState) { | ||
if (scrollY > flSink.getHeight()){ | ||
scrollerLayout.setStickyOffset(0); // 恢复吸顶偏移量 | ||
} else { | ||
// 通过设置吸顶便宜量,实现flSink滑动隐藏时的向上移动效果 | ||
scrollerLayout.setStickyOffset(-scrollY / 2); | ||
} | ||
} | ||
}); | ||
|
||
|
||
// 如果flSink不需要设置隐藏时的平移动画,就不用设置滑动监听和setStickyOffset | ||
|
||
// 如果要禁止滑动flSink来滑动整个布局,flSink不用设置app:layout_isTriggerScroll="true"即可。 | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/scrollerLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scrollbars="vertical"> | ||
|
||
<FrameLayout | ||
android:id="@+id/fl_sink" | ||
android:layout_width="match_parent" | ||
android:layout_height="400dp" | ||
app:layout_isSink="true" | ||
app:layout_isTriggerScroll="true" | ||
app:layout_isSticky="true"> | ||
|
||
<ImageView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scaleType="fitXY" | ||
android:src="@drawable/temp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="30dp" | ||
android:layout_marginRight="30dp" | ||
android:layout_marginTop="30dp" | ||
android:textColor="@android:color/white" | ||
android:textSize="16sp" | ||
android:text="这是个下沉的吸顶view,它不会被推出屏幕,而且覆盖隐藏在其他布局下面。"/> | ||
|
||
</FrameLayout> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
android:text="吸顶View - 1" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
app:layout_isSticky="true" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/recyclerView1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white"/> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
android:text="吸顶View - 2" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
app:layout_isSticky="true" /> | ||
|
||
<android.support.v4.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/holo_blue_bright" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="200dp" | ||
android:gravity="center" | ||
android:text="NestedScrollView" | ||
android:textColor="@android:color/black" | ||
android:textSize="24sp" /> | ||
|
||
</LinearLayout> | ||
</android.support.v4.widget.NestedScrollView> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
android:text="吸顶View - 3" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" | ||
app:layout_isSticky="true" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/recyclerView2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white"/> | ||
|
||
</com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout> |
Oops, something went wrong.