Java Code Examples for android.support.v4.widget.NestedScrollView#setOnScrollChangeListener()
The following examples show how to use
android.support.v4.widget.NestedScrollView#setOnScrollChangeListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollTransitionFragment.java From ClipPathLayout with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { mLayout = (NestedScrollView) inflater.inflate(R.layout.fragment_scroll_transition, null); mImageContainer = mLayout.findViewById(R.id.image_container); mBelowView = mLayout.findViewById(R.id.below_image); mAboveView = mLayout.findViewById(R.id.above_image); mLayout.setOnScrollChangeListener(this); mLayout.post(new Runnable() { @Override public void run() { if (mController == null) { initController(); } } }); return mLayout; }
Example 2
Source File: RefreshContentWrapper.java From CollapsingRefresh with Apache License 2.0 | 6 votes |
void attach(NestedScrollView scrollView) { //获得原始监听器,用作转发 Field[] declaredFields = NestedScrollView.class.getDeclaredFields(); if (declaredFields != null) { for (Field field : declaredFields) { if (NestedScrollView.OnScrollChangeListener.class.equals(field.getType())) { try { field.setAccessible(true); Object listener = field.get(scrollView); if (listener != null && !scrollView.equals(listener)) { mScrollChangeListener = (NestedScrollView.OnScrollChangeListener) listener; } } catch (IllegalAccessException e) { e.printStackTrace(); } } } } scrollView.setOnScrollChangeListener(this); }
Example 3
Source File: GoodsDetailsActivity.java From Sofia with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_goods_details); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); mHeaderView = findViewById(R.id.header); nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { int headerHeight = mHeaderView.getHeight(); int scrollDistance = Math.min(scrollY, headerHeight); int statusAlpha = (int) ((float) scrollDistance / (float) headerHeight * 255F); setAnyBarAlpha(statusAlpha); } }); Sofia.with(this) .statusBarBackground(ContextCompat.getColor(this, R.color.colorPrimary)) .navigationBarBackground(ContextCompat.getDrawable(this, R.color.colorNavigation)) .invasionStatusBar() .fitsStatusBarView(mToolbar); setAnyBarAlpha(0); }
Example 4
Source File: CommonActivity.java From Sofia with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_common); mToolbar = findViewById(R.id.toolbar); setSupportActionBar(mToolbar); NestedScrollView nestedScrollView = findViewById(R.id.nested_scroll_view); mHeaderView = findViewById(R.id.header); final int startColor = ContextCompat.getColor(this, R.color.colorPrimary); final int endColor = ContextCompat.getColor(this, R.color.colorNavigation); nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { int headerHeight = mHeaderView.getHeight(); int scrollDistance = Math.min(scrollY, headerHeight); float fraction = (float) scrollDistance / (float) headerHeight; setToolbarStatusBarAlpha(evaluate(fraction, startColor, endColor)); setNavigationViewColor(evaluate(fraction, endColor, startColor)); } }); Sofia.with(this) .statusBarBackground(ContextCompat.getColor(this, R.color.colorPrimary)) .navigationBarBackground(ContextCompat.getDrawable(this, R.color.colorNavigation)); }
Example 5
Source File: UserActivity.java From diycode with Apache License 2.0 | 5 votes |
private void initScrollAnimation(ViewHolder holder) { NestedScrollView scrollView = holder.get(R.id.scroll_view); ImageView avatar = holder.get(R.id.avatar); TextView username = holder.get(R.id.username); View backbground = holder.get(R.id.background); this.expectAnimMove = new ExpectAnim() .expect(avatar) .toBe( topOfParent().withMarginDp(13), leftOfParent().withMarginDp(13), scale(0.5f, 0.5f) ) .expect(username) .toBe( toRightOf(avatar).withMarginDp(16), sameCenterVerticalAs(avatar), alpha(0.5f) ) .expect(backbground) .toBe( height(DensityUtils.dip2px(this, 60)).withGravity(Gravity.LEFT, Gravity.TOP) ) .toAnimation(); scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { final float percent = (scrollY * 1f) / v.getMaxScrollAmount(); expectAnimMove.setPercent(percent); } }); }
Example 6
Source File: MaterialViewPagerAnimator.java From MaterialViewPager with Apache License 2.0 | 5 votes |
/** * Register a ScrollView to the current MaterialViewPagerAnimator * Listen to ObservableScrollViewCallbacks so give to $[observableScrollViewCallbacks] your ObservableScrollViewCallbacks if you already use one * For loadmore or anything else * * @param scrollView the scrollable */ void registerScrollView(final NestedScrollView scrollView) { if (scrollView != null) { scrollViewList.add(scrollView); //add to the scrollable list scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { boolean firstZeroPassed; @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { //first time you get 0, don't share it to others scrolls if (scrollY == 0 && !firstZeroPassed) { firstZeroPassed = true; return; } //only if yOffset changed if (isNewYOffset(scrollY)) { onMaterialScrolled(scrollView, scrollY); } } }); scrollView.post(new Runnable() { @Override public void run() { setScrollOffset(scrollView, lastYOffset); } }); } }
Example 7
Source File: ScrollCollapseLargeToolbarActivity.java From CoordinatorLayoutSample with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scroll_collapse_large_toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); String toolbarTitle = getResources().getString(R.string.sample_collapse_scroll_toolbar); CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle(toolbarTitle); mFab = findViewById(R.id.fab); NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scrollview); scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (scrollY > oldScrollY) { animateFab(false); } else { animateFab(true); } } }); }
Example 8
Source File: NoteDetailBaseActivity.java From nono-android with GNU General Public License v3.0 | 4 votes |
@Override protected void registerWidget() { note_detail_groupname =$(R.id.note_detail_groupname) ; note_detail_groupname.setText(currentNoteInfo.title); real_toolbar =$(R.id.real_toolbar) ; note_detail_time =$(R.id.note_detail_time) ; editFab = $(R.id.edit_fab); new Handler().postDelayed(new Runnable() { @Override public void run() { showHelp(editFab); } },1000); bindViewsToOnClickListenerById(R.id.note_detail_content,R.id.edit_fab); NestedScrollView nestedScrollView = getNestedScrollView(); if(nestedScrollView == null){ Log.e(NONoConfig.TAG_NONo,"note detail activity must have at lease one NestedScrollView"); }else { nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { int dy = scrollY - oldScrollY; if (dy < 0) { if (magicFlag) { magicFlag = !magicFlag; editFab.setVisibility(View.VISIBLE); } } else if (dy > 0) { if (!magicFlag) { magicFlag = !magicFlag; editFab.setVisibility(View.INVISIBLE); } } } }); } //iniFAB(); if(((TextView)$(R.id.note_detail_text_num)).getText().toString().equals("0")){ showTextNum(currentNoteInfo.content); } }