Das ist mein Layout:
Code: Select all
Code: Select all
homeViewedLL = (LinearLayout) view.findViewById(R.id.viewedHomeLL);
float density = getResources().getDisplayMetrics().density;
final int[] totalScrollY = {0};
final boolean[] headerCollapsed = {false};
recycleviewHome.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int maxCollapsePx = (int) (homeViewedLL.getHeight() * density); // how much the header can move up
totalScrollY[0] += dy;
totalScrollY[0] = Math.max(0, Math.min(totalScrollY[0], maxCollapsePx));
// Move header up (translation is smoother than changing margin)
homeViewedLL.setTranslationY(-totalScrollY[0]);
// Detect when header is fully collapsed
if (totalScrollY[0] >= maxCollapsePx && !headerCollapsed[0]) {
headerCollapsed[0] = true;
}
// Detect when header expands again
else if (totalScrollY[0] < maxCollapsePx && headerCollapsed[0]) {
headerCollapsed[0] = false;
}
}
});
Gibt es eine Möglichkeit, das Problem zu beheben?
Lassen Sie mich wissen, wenn Sie weitere Informationen benötigen.
Mobile version