diff --git a/app/build.gradle b/app/build.gradle
index 753e268..e817066 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -22,6 +22,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
+ implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 79c9e3d..626284f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,9 +11,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
+
+
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MainActivity.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MainActivity.java
index 58bc084..188e376 100644
--- a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MainActivity.java
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MainActivity.java
@@ -37,6 +37,14 @@ public void onClick(View v) {
}
});
+ findViewById(R.id.btn_viewpager).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this,ViewPagerActivity.class);
+ startActivity(intent);
+ }
+ });
+
}
}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.java
index b87aa4c..d63f5c4 100644
--- a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.java
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.java
@@ -11,34 +11,25 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter;
-import com.donkingliang.consecutivescrollerdemo.widget.MyRecyclerView;
/**
- * @Author teach-梁任彦
+ * @Author donkingliang
* @Description
* @Date 2020/4/18
*/
public class MyFragment extends Fragment {
- private ConsecutiveScrollerLayout mScrollerLayout;
-
- public MyFragment(ConsecutiveScrollerLayout scrollerLayout) {
- this.mScrollerLayout = scrollerLayout;
- }
-
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list,container,false);
- MyRecyclerView list = view.findViewById(R.id.list);
+ RecyclerView list = view.findViewById(R.id.list);
list.setLayoutManager(new LinearLayoutManager(getContext()));
RecyclerViewAdapter adapter = new RecyclerViewAdapter(getContext(),"ViewPager1-");
list.setAdapter(adapter);
- list.setScrollerLayout(mScrollerLayout);
return view;
}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/StickyActivity.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/StickyActivity.java
index 9b97a2d..3cf1350 100644
--- a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/StickyActivity.java
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/StickyActivity.java
@@ -1,11 +1,8 @@
package com.donkingliang.consecutivescrollerdemo;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.webkit.WebChromeClient;
@@ -44,24 +41,10 @@ public void onProgressChanged(WebView view, int newProgress) {
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);
-
- ViewPager viewPager = findViewById(R.id.viewPager);
- viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
- @Override
- public Fragment getItem(int position) {
- return new MyFragment(scrollerLayout);
- }
-
- @Override
- public int getCount() {
- return 4;
- }
- });
-
+ RecyclerView recyclerView2 = findViewById(R.id.recyclerView2);
+ recyclerView2.setLayoutManager(new LinearLayoutManager(this));
+ RecyclerViewAdapter adapter2 = new RecyclerViewAdapter(this,"RecyclerView2-");
+ recyclerView2.setAdapter(adapter2);
}
}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPagerActivity.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPagerActivity.java
new file mode 100644
index 0000000..ecb2026
--- /dev/null
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPagerActivity.java
@@ -0,0 +1,51 @@
+package com.donkingliang.consecutivescrollerdemo;
+
+import android.os.Bundle;
+import android.widget.TextView;
+
+import com.donkingliang.consecutivescrollerdemo.adapter.TabPagerAdapter;
+import com.google.android.material.tabs.TabLayout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+import androidx.viewpager.widget.ViewPager;
+
+public class ViewPagerActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_viewpager);
+
+ TextView text = findViewById(R.id.text);
+ text.setText("子view实现IConsecutiveScroller接口,并通过实现接口方法告诉ConsecutiveScrollerLayout需要滑动的下级view,\n" +
+ " * ConsecutiveScrollerLayout就能正确地处理它的滑动事件。");
+ ViewPager viewPager = findViewById(R.id.viewPager);
+ TabLayout tabLayout = findViewById(R.id.tabLayout);
+ viewPager.setAdapter(new TabPagerAdapter(getSupportFragmentManager(), getTabs(), getFragments()));
+ tabLayout.setupWithViewPager(viewPager);
+ }
+
+ private List getTabs() {
+ List tabs = new ArrayList<>();
+ tabs.add("Tab1");
+ tabs.add("Tab2");
+ tabs.add("Tab3");
+ tabs.add("Tab4");
+ tabs.add("Tab5");
+ return tabs;
+ }
+
+ private List getFragments() {
+ List fragmentList = new ArrayList<>();
+ fragmentList.add(new MyFragment());
+ fragmentList.add(new MyFragment());
+ fragmentList.add(new MyFragment());
+ fragmentList.add(new MyFragment());
+ fragmentList.add(new MyFragment());
+ return fragmentList;
+ }
+}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/TabPagerAdapter.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/TabPagerAdapter.java
new file mode 100644
index 0000000..3a9ee29
--- /dev/null
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/TabPagerAdapter.java
@@ -0,0 +1,38 @@
+package com.donkingliang.consecutivescrollerdemo.adapter;
+
+
+import java.util.List;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentStatePagerAdapter;
+
+/**
+ * Depiction: TabLayout 和 Fragment,viewpager结合使用的viewpager adapter。
+ */
+public class TabPagerAdapter extends FragmentStatePagerAdapter {
+
+ private List mTitles;
+ private List extends Fragment> mFragments;
+
+ public TabPagerAdapter(FragmentManager fm, List titleList, List extends Fragment> fragments) {
+ super(fm);
+ this.mTitles = titleList;
+ this.mFragments = fragments;
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return mFragments.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mFragments == null ? 0 : mFragments.size();
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ return mTitles == null ? "" : mTitles.get(position);
+ }
+}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyRecyclerView.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyRecyclerView.java
deleted file mode 100644
index 1ea06f2..0000000
--- a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyRecyclerView.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.donkingliang.consecutivescrollerdemo.widget;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.ViewParent;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.recyclerview.widget.RecyclerView;
-
-import com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout;
-
-/**
- * @Author teach-梁任彦
- * @Description
- * @Date 2020/4/18
- */
-public class MyRecyclerView extends RecyclerView {
-
- private ConsecutiveScrollerLayout mScrollerLayout;
-
- private int mTouchY;
-
- public MyRecyclerView(@NonNull Context context) {
- super(context);
- }
-
- public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
- }
-
- public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- public void setScrollerLayout(ConsecutiveScrollerLayout layout){
- mScrollerLayout = layout;
- }
-
-
-}
diff --git a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyViewPager.java b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyViewPager.java
index e2925db..689e333 100644
--- a/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyViewPager.java
+++ b/app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyViewPager.java
@@ -14,7 +14,7 @@
import java.util.List;
/**
- * @Author teach-梁任彦
+ * @Author donkingliang
* @Description
* @Date 2020/4/18
*/
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 66d31f6..274857d 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -2,8 +2,8 @@
+ android:gravity="center"
+ android:orientation="vertical">
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_sticky.xml b/app/src/main/res/layout/activity_sticky.xml
index 1c325ae..4b1d4a0 100644
--- a/app/src/main/res/layout/activity_sticky.xml
+++ b/app/src/main/res/layout/activity_sticky.xml
@@ -14,7 +14,7 @@
android:text="吸顶View - 1"
android:textColor="@android:color/black"
android:textSize="18sp"
- app:layout_isSticky="false" />
+ app:layout_isSticky="true" />
+ app:layout_isSticky="true">
+ app:layout_isSticky="true" />
+ app:layout_isSticky="true" />
-
+ android:layout_height="wrap_content" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_viewpager.xml b/app/src/main/res/layout/activity_viewpager.xml
new file mode 100644
index 0000000..635de5a
--- /dev/null
+++ b/app/src/main/res/layout/activity_viewpager.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_item_list.xml b/app/src/main/res/layout/fragment_item_list.xml
index ddde4be..f9327fd 100644
--- a/app/src/main/res/layout/fragment_item_list.xml
+++ b/app/src/main/res/layout/fragment_item_list.xml
@@ -1,7 +1,7 @@
-
+ android:layout_marginRight="16dp" />