N

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

final int initialLinear1Top = linear1.

getTop();

vscroll3.setOnScrollChangeListener(new
NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int
scrollY, int oldScrollX, int oldScrollY) {

int lastScrollY = 0;
int scrollThreshold = dpToPx(200);

int scrollDistance = scrollY - lastScrollY;

if (scrollDistance > 0) {

if (scrollDistance < scrollThreshold) {

linear1.setBackgroundColor(0x80000000);

requireActivity().getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
Window w = requireActivity(). getWindow();

w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
w.setStatusBarColor(Color.parseColor("#00000000"));

} else {

linear1.setBackgroundColor(Color.TRANSPARENT);

requireActivity().getWindow()
.getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
Window w = requireActivity(). getWindow();

w.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
w.setStatusBarColor(Color.parseColor("#00000000"));

}
}

lastScrollY = scrollY;
linear1.setTranslationY(scrollY - initialLinear1Top);
/* if (scrollY > initialLinear1Top) {
linear1.setTranslationY(scrollY - initialLinear1Top);
} else {
linear1.setTranslationY(0);
}*/
}

private int dpToPx(int dp) {


float density = getResources().getDisplayMetrics().density;
return Math.round(dp * density);
}
});

You might also like