forked from donkingliang/ConsecutiveScroller
-
Notifications
You must be signed in to change notification settings - Fork 0
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
f11928e
commit a77f015
Showing
13 changed files
with
160 additions
and
88 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
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
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.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<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; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,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<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); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
app/src/main/java/com/donkingliang/consecutivescrollerdemo/widget/MyRecyclerView.java
This file was deleted.
Oops, something went wrong.
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
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" /> | ||
|
||
<com.google.android.material.tabs.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.donkingliang.consecutivescrollerdemo.widget.MyRecyclerView xmlns:android="http://schemas.android.com/apk/res/android" | ||
<androidx.recyclerview.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"/> | ||
android:layout_marginRight="16dp" /> |