效果
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
<LinearLayout
android:id="@+id/home_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/theme_color"
android:paddingBottom="10dp"
android:layout_alignParentStart="true">
<include layout="@layout/home_header"/>
</LinearLayout>
</RelativeLayout>
private void initListener(){
rvHome.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
scrollY += dy;
float alpha = Float.valueOf(scrollY) / 1000f * 255f;
homeHeader.getBackground().setAlpha((int)alpha > 255 ? 255 : (int)alpha);
}
});
}
任何艰辛都为了实现心中梦
|