https://blog.kyleduo.com/2017/07/21/alipay-home-3-alipay-home/
平滑
https://github.com/leifu1107/AlipayHome
有点那啥 但是那啥
开始实践~
https://github.com/zhangqifan1/Demo_ok9
implementation 'com.android.support:design:28.0.0'
widgts 包 粘贴~改改import decarition 不用可以删 其他 都是 核心~看不懂的;了
ids 也得粘贴
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.as.alipayhome.widgets.APHeaderView
android:id="@+id/alipay_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.as.alipayhome.widgets.APSnapView
android:id="@id/alipay_snap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:background="#f0f0"
android:gravity="center"
android:text="我是内容内容可以自定义,一会我就盖上去,嘿嘿"
android:textStyle="bold"
android:textSize="22sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.as.alipayhome.widgets.APSnapView>
<LinearLayout
android:background="#f050f0"
android:id="@+id/alipay_grid_menu"
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical">
<TextView
android:gravity="center"
android:text="不盖上去,只是顶上去,,可以当RecyclerView首条目"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
<com.as.alipayhome.widgets.APBarView
android:id="@id/alipay_bar"
android:layout_width="match_parent"
android:layout_height="48dp"
>
<LinearLayout
android:id="@+id/bar1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:background="#ff0"
android:gravity="center"
android:text="顶上去会显示"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/bar2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:background="#f00"
android:gravity="center"
android:text="顶上去会隐藏"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</com.as.alipayhome.widgets.APBarView>
</com.as.alipayhome.widgets.APHeaderView>
<android.support.v7.widget.RecyclerView
android:id="@+id/alipay_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.as.alipayhome.widgets.APScrollingBehavior"
android:overScrollMode="never"/>
</android.support.design.widget.CoordinatorLayout>
注意xml 里 和 ids 一样的 id 就一样吧 不出幺蛾子~
这里短暂的一瞬间空白 是因为 俩个View /bar1 bar2 的 透明度 啥的 都到了极限 所以 只会显示背景色 我的白色的 支付宝的蓝色的 So
MainAc
public class MainActivity extends AppCompatActivity {
RecyclerView mRecyclerView;
APHeaderView mHeaderView;
AlipayAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.alipay_rv);
mHeaderView = (APHeaderView) findViewById(R.id.alipay_header);
final LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) {
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
int scrolled = super.scrollVerticallyBy(dy, recycler, state);
if (dy < 0 && scrolled != dy) {
// 有剩余
APHeaderView.Behavior behavior = mHeaderView.getBehavior();
if (behavior != null) {
int unconsumed = dy - scrolled;
int consumed = behavior.scroll((CoordinatorLayout) mHeaderView.getParent(), mHeaderView, unconsumed, -mHeaderView.getScrollRange(), 0);
scrolled += consumed;
}
}
return scrolled;
}
};
mHeaderView.setOnHeaderFlingUnConsumedListener(new APHeaderView.OnHeaderFlingUnConsumedListener() {
@Override
public int onFlingUnConsumed(APHeaderView header, int targetOffset, int unconsumed) {
APHeaderView.Behavior behavior = mHeaderView.getBehavior();
int dy = -unconsumed;
if (behavior != null) {
mRecyclerView.scrollBy(0, dy);
}
return dy;
}
});
ArrayList<String> titles = new ArrayList<>();
for (int i = 0; i < 30; i++) {
titles.add("item " + i);
}
mRecyclerView.setLayoutManager(lm);
mAdapter = new AlipayAdapter(titles);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new CommonListDecoration());
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
APHeaderView.Behavior behavior = mHeaderView.getBehavior();
if (behavior != null) {
behavior.checkSnap((CoordinatorLayout) mHeaderView.getParent(), mHeaderView);
}
}
}
});
}
static class AlipayItemViewHolder extends RecyclerView.ViewHolder {
TextView titleTv;
public AlipayItemViewHolder(View itemView) {
super(itemView);
titleTv = (TextView) itemView;
}
}
private static class AlipayAdapter extends RecyclerView.Adapter<AlipayItemViewHolder> {
private List<String> mTitles;
public AlipayAdapter(List<String> titles) {
mTitles = titles;
}
@Override
public AlipayItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new AlipayItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_content, parent, false));
}
@Override
public void onBindViewHolder(AlipayItemViewHolder holder, int position) {
holder.titleTv.setText(mTitles.get(position));
}
@Override
public int getItemCount() {
return mTitles == null ? 0 : mTitles.size();
}
}
}