-
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
Apr 20, 2020
1 parent
fa933dc
commit 3471a52
Showing
14 changed files
with
277 additions
and
6 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
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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/donkingliang/consecutivescrollerdemo/MyFragment.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,35 @@ | ||
package com.donkingliang.consecutivescrollerdemo; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.donkingliang.consecutivescrollerdemo.adapter.RecyclerViewAdapter; | ||
|
||
/** | ||
* @Author donkingliang | ||
* @Description | ||
* @Date 2020/4/18 | ||
*/ | ||
public class MyFragment extends Fragment { | ||
|
||
@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); | ||
|
||
RecyclerView list = view.findViewById(R.id.list); | ||
list.setLayoutManager(new LinearLayoutManager(getContext())); | ||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(getContext(),"ViewPager1-"); | ||
list.setAdapter(adapter); | ||
return view; | ||
|
||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/donkingliang/consecutivescrollerdemo/ViewPagerActivity.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,51 @@ | ||
package com.donkingliang.consecutivescrollerdemo; | ||
|
||
import android.os.Bundle; | ||
import android.support.design.widget.TabLayout; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.TextView; | ||
|
||
import com.donkingliang.consecutivescrollerdemo.adapter.TabPagerAdapter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
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的下级view的滑动事件。\n" + | ||
"下面的例子中,通过自定义ViewPager,实现IConsecutiveScroller接口,ConsecutiveScrollerLayout能正确的处理ViewPager里" + | ||
"的RecyclerView滑动,使RecyclerView与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<String> getTabs() { | ||
List<String> tabs = new ArrayList<>(); | ||
tabs.add("Tab1"); | ||
tabs.add("Tab2"); | ||
tabs.add("Tab3"); | ||
tabs.add("Tab4"); | ||
tabs.add("Tab5"); | ||
return tabs; | ||
} | ||
|
||
private List<Fragment> getFragments() { | ||
List<Fragment> 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; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/donkingliang/consecutivescrollerdemo/adapter/TabPagerAdapter.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,39 @@ | ||
package com.donkingliang.consecutivescrollerdemo.adapter; | ||
|
||
|
||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentStatePagerAdapter; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Depiction: TabLayout 和 Fragment,viewpager结合使用的viewpager adapter。 | ||
*/ | ||
public class TabPagerAdapter extends FragmentStatePagerAdapter { | ||
|
||
private List<String> mTitles; | ||
private List<? extends Fragment> mFragments; | ||
|
||
public TabPagerAdapter(FragmentManager fm, List<String> 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); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyViewPager.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,63 @@ | ||
package com.donkingliang.consecutivescrollerdemo.widget; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.view.ViewPager; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
|
||
import com.donkingliang.consecutivescroller.IConsecutiveScroller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* @Author donkingliang | ||
* @Description | ||
* @Date 2020/4/18 | ||
*/ | ||
public class MyViewPager extends ViewPager implements IConsecutiveScroller { | ||
public MyViewPager(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
public MyViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
/** | ||
* 返回当前需要滑动的view。 | ||
* 注意:这个view不一定是ViewPager的直接子view,使用者应该根据自己的业务情况返回需要滑动的下级view。 | ||
* @return | ||
*/ | ||
@Override | ||
public View getCurrentScrollerView() { | ||
int count = getChildCount(); | ||
for (int i = 0; i < count; i++) { | ||
View view = getChildAt(i); | ||
if (view.getX() == getScrollX()) { | ||
return view; | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* 返回全部需要滑动的下级view | ||
* @return | ||
*/ | ||
@Override | ||
public List<View> getScrolledViews() { | ||
List<View> views = new ArrayList<>(); | ||
int count = getChildCount(); | ||
if (count > 0) { | ||
for (int i = 0; i < count; i++) { | ||
views.add(getChildAt(i)); | ||
} | ||
} else { | ||
views.add(this); | ||
} | ||
return views; | ||
} | ||
} |
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
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,35 @@ | ||
<?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"> | ||
|
||
<TextView | ||
android:id="@+id/text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
android:textColor="@android:color/black" | ||
android:textSize="18sp" /> | ||
|
||
<android.support.design.widget.TabLayout | ||
android:id="@+id/tabLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/white" | ||
app:layout_isSticky="true" | ||
app:tabGravity="fill" | ||
app:tabIndicatorColor="@color/colorPrimary" | ||
app:tabIndicatorHeight="3dp" | ||
app:tabMode="scrollable" | ||
app:tabSelectedTextColor="@color/colorPrimary" /> | ||
|
||
<com.donkingliang.consecutivescrollerdemo.widget.MyViewPager | ||
android:id="@+id/viewPager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout> |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/item_number" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/text_margin" | ||
android:textAppearance="?attr/textAppearanceListItem" /> | ||
|
||
<TextView | ||
android:id="@+id/content" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/text_margin" | ||
android:textAppearance="?attr/textAppearanceListItem" /> | ||
</LinearLayout> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginLeft="16dp" | ||
android:layout_marginRight="16dp" /> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="text_margin">16dp</dimen> | ||
</resources> |