Skip to content

Commit

Permalink
添加下沉模式吸顶view;同步master
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Sep 11, 2020
1 parent ffbbd69 commit 89f60f6
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 34 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:theme="@style/AppTheme">
<activity android:name=".ConsecutiveActivity"/>
<activity android:name=".StickyActivity" />
<activity android:name=".SinkStickyActivity" />
<activity android:name=".SampleActivity" />
<activity android:name=".ViewPagerActivity" />
<activity android:name=".PermanentStickyActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public void onClick(View v) {
}
});

findViewById(R.id.btn_sink_sticky).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,SinkStickyActivity.class);
startActivity(intent);
}
});

findViewById(R.id.btn_consecutive).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
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"即可。
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
android:layout_height="wrap_content"
android:text="布局吸顶常驻" />

<Button
android:id="@+id/btn_sink_sticky"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="吸顶下沉模式" />

<Button
android:id="@+id/btn_consecutive"
android:layout_width="wrap_content"
Expand Down
139 changes: 139 additions & 0 deletions app/src/main/res/layout/activity_sink_sticky.xml
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>
Loading

0 comments on commit 89f60f6

Please sign in to comment.