react-native-navigation的迁移库

CollapsingTitleBar.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.reactnativenavigation.views.collapsingToolbar;
  2. import android.content.Context;
  3. import android.view.MotionEvent;
  4. import android.view.View;
  5. import com.reactnativenavigation.params.StyleParams;
  6. import com.reactnativenavigation.views.TitleBar;
  7. public class CollapsingTitleBar extends TitleBar implements View.OnTouchListener {
  8. private CollapsingTextView title;
  9. private int collapsedHeight;
  10. private final ScrollListener scrollListener;
  11. public CollapsingTitleBar(Context context, int collapsedHeight, ScrollListener scrollListener) {
  12. super(context);
  13. this.collapsedHeight = collapsedHeight;
  14. this.scrollListener = scrollListener;
  15. addCollapsingTitle();
  16. setOnTouchListener(this);
  17. }
  18. private void addCollapsingTitle() {
  19. title = new CollapsingTextView(getContext(), collapsedHeight);
  20. addView(title);
  21. }
  22. @Override
  23. public void setTitle(CharSequence title) {
  24. this.title.setText((String) title);
  25. }
  26. @Override
  27. protected void setTitleTextColor(StyleParams params) {
  28. title.setTextColor(params);
  29. }
  30. @Override
  31. protected void setSubtitleTextColor(StyleParams params) {
  32. }
  33. public void collapse(float collapse) {
  34. title.setTranslationY(0);
  35. setTranslationY(-collapse);
  36. title.collapseBy(collapse);
  37. }
  38. @Override
  39. public boolean onTouch(View v, MotionEvent event) {
  40. return scrollListener.onTouch(event);
  41. }
  42. }