-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add demo CoordinatorLayout 嵌套滑动置顶(原始方案)
- Loading branch information
1 parent
96ff7c2
commit 6a799d2
Showing
7 changed files
with
282 additions
and
1 deletion.
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
76 changes: 76 additions & 0 deletions
76
...src/main/java/me/jingbin/byrecyclerview/activity/StickyRvCoordinatorOriginalActivity.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,76 @@ | ||
package me.jingbin.byrecyclerview.activity; | ||
|
||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.fragment.app.Fragment; | ||
|
||
import com.scwang.smartrefresh.layout.api.RefreshLayout; | ||
import com.scwang.smartrefresh.layout.listener.OnRefreshListener; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
|
||
import me.jingbin.byrecyclerview.R; | ||
import me.jingbin.byrecyclerview.app.BaseActivity; | ||
import me.jingbin.byrecyclerview.databinding.ActivityStickyRvCoordBinding; | ||
import me.jingbin.byrecyclerview.databinding.ActivityStickyRvCoordOriginalBinding; | ||
import me.jingbin.byrecyclerview.fragment.CoordinatorOriginalFragment; | ||
import me.jingbin.byrecyclerview.fragment.RefreshFragment; | ||
import me.jingbin.byrecyclerview.fragment.SwipeRefreshFragment; | ||
import me.jingbin.byrecyclerview.stickrvcool.config.FeedsPagerAdapter; | ||
import me.jingbin.byrecyclerview.stickrvcool.config.HomeIndicatorHelper; | ||
import me.jingbin.byrecyclerview.view.MyFragmentPagerAdapter; | ||
|
||
/** | ||
* @author jingbin | ||
* CoordinatorLayout 嵌套滑动置顶(原始方案) | ||
*/ | ||
public class StickyRvCoordinatorOriginalActivity extends BaseActivity<ActivityStickyRvCoordOriginalBinding> { | ||
|
||
private final ArrayList<String> mTitleList = new ArrayList<>(5); | ||
private final ArrayList<Fragment> mFragments = new ArrayList<>(5); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_sticky_rv_coord_original); | ||
setTitle("CoordinatorLayout 嵌套滑动置顶"); | ||
initView(); | ||
} | ||
|
||
private void initView() { | ||
initFragmentList(); | ||
MyFragmentPagerAdapter myAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragments, mTitleList); | ||
binding.viewPager.setAdapter(myAdapter); | ||
binding.viewPager.setOffscreenPageLimit(mTitleList.size() - 1); | ||
myAdapter.notifyDataSetChanged(); | ||
binding.tabLayout.setupWithViewPager(binding.viewPager); | ||
binding.mainRefreshLayout.setOnRefreshListener(new OnRefreshListener() { | ||
@Override | ||
public void onRefresh(@NonNull @NotNull RefreshLayout refreshLayout) { | ||
binding.mainRefreshLayout.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
binding.mainRefreshLayout.finishRefresh(); | ||
} | ||
}, 1000); | ||
} | ||
}); | ||
} | ||
|
||
private void initFragmentList() { | ||
mTitleList.clear(); | ||
mTitleList.add("关注"); | ||
mTitleList.add("推荐"); | ||
mTitleList.add("直播"); | ||
mTitleList.add("进口"); | ||
mTitleList.add("实惠"); | ||
mFragments.add(CoordinatorOriginalFragment.newInstance("")); | ||
mFragments.add(CoordinatorOriginalFragment.newInstance("")); | ||
mFragments.add(CoordinatorOriginalFragment.newInstance("")); | ||
mFragments.add(CoordinatorOriginalFragment.newInstance("")); | ||
mFragments.add(CoordinatorOriginalFragment.newInstance("")); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
app/src/main/java/me/jingbin/byrecyclerview/fragment/CoordinatorOriginalFragment.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,110 @@ | ||
package me.jingbin.byrecyclerview.fragment; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import androidx.recyclerview.widget.StaggeredGridLayoutManager; | ||
|
||
import me.jingbin.byrecyclerview.R; | ||
import me.jingbin.byrecyclerview.adapter.DataAdapter; | ||
import me.jingbin.byrecyclerview.adapter.FeedStaggerAdapter; | ||
import me.jingbin.byrecyclerview.bean.DataItemBean; | ||
import me.jingbin.byrecyclerview.databinding.FragmentRefreshBinding; | ||
import me.jingbin.byrecyclerview.utils.DataUtil; | ||
import me.jingbin.byrecyclerview.utils.DensityUtil; | ||
import me.jingbin.byrecyclerview.utils.ToastUtil; | ||
import me.jingbin.library.ByRecyclerView; | ||
import me.jingbin.library.decoration.GridSpaceItemDecoration; | ||
import me.jingbin.library.decoration.SpacesItemDecoration; | ||
import me.jingbin.library.view.OnItemFilterClickListener; | ||
|
||
/** | ||
* @author jingbin | ||
*/ | ||
public class CoordinatorOriginalFragment extends BaseFragment<FragmentRefreshBinding> { | ||
|
||
private static final String TYPE = "mType"; | ||
private String mType = "Android"; | ||
private boolean mIsPrepared; | ||
private boolean mIsFirst = true; | ||
private FeedStaggerAdapter feedStaggerAdapter; | ||
private int page = 0; | ||
|
||
|
||
@Override | ||
public void onAttach(Context context) { | ||
super.onAttach(context); | ||
} | ||
|
||
public static CoordinatorOriginalFragment newInstance(String type) { | ||
CoordinatorOriginalFragment fragment = new CoordinatorOriginalFragment(); | ||
Bundle args = new Bundle(); | ||
args.putString(TYPE, type); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if (getArguments() != null) { | ||
mType = getArguments().getString(TYPE); | ||
} | ||
} | ||
|
||
@Override | ||
public int setContent() { | ||
return R.layout.fragment_refresh; | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
|
||
// 准备就绪 | ||
mIsPrepared = true; | ||
initAdapter(); | ||
} | ||
|
||
@Override | ||
protected void loadData() { | ||
if (!mIsPrepared || !mIsVisible || !mIsFirst) { | ||
return; | ||
} | ||
initAdapter(); | ||
} | ||
|
||
private void initAdapter() { | ||
binding.recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, RecyclerView.VERTICAL)); | ||
binding.recyclerView.addItemDecoration(new GridSpaceItemDecoration(DensityUtil.dip2px(activity, 8f))); | ||
feedStaggerAdapter = new FeedStaggerAdapter((DataUtil.getStickyData())); | ||
binding.recyclerView.setAdapter(feedStaggerAdapter); | ||
binding.recyclerView.setOnItemClickListener(new OnItemFilterClickListener() { | ||
@Override | ||
protected void onSingleClick(View v, int position) { | ||
if ("点我回到顶部".equals(feedStaggerAdapter.getItemData(position).getTitle())) { | ||
binding.recyclerView.scrollToPosition(0); | ||
} | ||
} | ||
}); | ||
// 设置自动刷新 | ||
binding.recyclerView.setOnLoadMoreListener(true, 1, new ByRecyclerView.OnLoadMoreListener() { | ||
@Override | ||
public void onLoadMore() { | ||
if (page == 2) { | ||
binding.recyclerView.loadMoreEnd(); | ||
return; | ||
} | ||
page = 2; | ||
feedStaggerAdapter.addData(DataUtil.getStickyData()); | ||
binding.recyclerView.loadMoreComplete(); | ||
} | ||
}, 1000); | ||
|
||
mIsFirst = false; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/res/layout/activity_sticky_rv_coord_original.xml
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,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<!--app:srlEnableOverScrollBounce="false" 关闭越界回弹功能--> | ||
<com.scwang.smartrefresh.layout.SmartRefreshLayout | ||
android:id="@+id/main_refresh_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/main_toolbar" | ||
app:srlAccentColor="#fff" | ||
app:srlReboundDuration="600"> | ||
|
||
<com.scwang.smartrefresh.layout.header.ClassicsHeader | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:srlAccentColor="@color/color_4" | ||
app:srlEnableLastTime="false" /> | ||
|
||
<!--coordinator部分--> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout | ||
android:id="@+id/main_coordinator_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:id="@+id/main_appbar_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@android:color/transparent" | ||
android:fadingEdge="none" | ||
app:elevation="0dp" | ||
app:layout_behavior=".view.FlingBehavior" | ||
app:layout_scrollFlags="scroll|enterAlways" | ||
tools:ignore="WebViewLayout"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:layout_scrollFlags="scroll|exitUntilCollapsed"> | ||
|
||
<include layout="@layout/layout_skeleton_headerview" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
<com.google.android.material.tabs.TabLayout | ||
android:id="@+id/tabLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:layout_below="@+id/tv_name_tool" | ||
android:background="@color/colorWhite" | ||
android:visibility="visible" | ||
app:tabIndicatorColor="@color/colorPrimary" | ||
app:tabIndicatorHeight="2dp" | ||
app:tabMode="fixed" | ||
app:tabSelectedTextColor="@color/colorPrimary" | ||
app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" /> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<!--商品流--> | ||
<me.jingbin.byrecyclerview.view.ViewPagerFixed | ||
android:id="@+id/viewPager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#f3f3f3" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> | ||
|
||
</com.scwang.smartrefresh.layout.SmartRefreshLayout> | ||
|
||
|
||
</layout> |