Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. /**
  2. * Created by Saurabh(aqua) in 2017.
  3. */
  4.  
  5. public class ScrollActivity extends BaseActivity {
  6.  
  7. /* view binding */
  8. @BindView(R.id.scrollView)ScrollView scrollView;
  9. @BindView(R.id.parallax_image)ImageView parallaxImage;
  10. @BindView(R.id.tv_perhour)TextView textView;
  11. @BindView(R.id.tv_heading)TextView heading;
  12. /* color binding */
  13. @BindColor(R.color.white)int whiteColor;
  14. @BindColor(android.R.color.transparent)int transparentColor;
  15.  
  16. @Override
  17. protected void onCreate(@Nullable Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. /* intially hide the view */
  20. heading.setAlpha(0f);
  21. /* set the scroll change listener on scrollview */
  22. scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
  23. @Override
  24. public void onScrollChanged() {
  25. /* get the maximum height which we have scroll before performing any action */
  26. int maxDistance = parallaxImage.getHeight();
  27. /* how much we have scrolled */
  28. int movement = scrollView.getScrollY();
  29. /*finally calculate the alpha factor and set on the view */
  30. float alphaFactor = ((movement * 1.0f) / (maxDistance - heading.getHeight()));
  31. if (movement >= 0 && movement <= maxDistance) {
  32. /*for image parallax with scroll */
  33. parallaxImage.setTranslationY(-movement/2);
  34. /* set visibility */
  35. heading.setAlpha(alphaFactor);
  36. }
  37. }
  38. });
  39. }
  40.  
  41. /* can be replaced with setContentView() in onCreate() */
  42. /* kept for brevity */
  43. @Override
  44. protected int getActivityLayout() {
  45. return R.layout.ac_parallax;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement