Search in sources :

Example 6 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project smooth-app-bar-layout by henrytao-me.

the class Utils method syncOffset.

public static boolean syncOffset(SmoothAppBarLayout smoothAppBarLayout, View target, int verticalOffset, View scroll) {
    boolean isSelected = target == scroll;
    if (scroll instanceof NestedScrollView) {
        NestedScrollView nestedScrollView = (NestedScrollView) scroll;
        if (nestedScrollView.getScrollY() < verticalOffset || (!isSelected && isScrollToTop(target))) {
            nestedScrollView.scrollTo(0, verticalOffset);
        }
        if (isSelected && (nestedScrollView.getScrollY() < verticalOffset || verticalOffset == 0)) {
            nestedScrollView.scrollTo(0, 0);
            smoothAppBarLayout.syncOffset(0);
        }
    } else if (scroll instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) scroll;
        boolean isAccuracy = recyclerView.getLayoutManager().findViewByPosition(ObservableRecyclerView.HEADER_VIEW_POSITION) != null;
        if (isAccuracy && recyclerView.computeVerticalScrollOffset() < verticalOffset) {
            recyclerView.scrollBy(0, verticalOffset - recyclerView.computeVerticalScrollOffset());
        } else if (!isSelected && isScrollToTop(target)) {
            recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
        }
        if (isAccuracy && isSelected && (recyclerView.computeVerticalScrollOffset() < verticalOffset || verticalOffset == 0)) {
            recyclerView.scrollToPosition(ObservableRecyclerView.HEADER_VIEW_POSITION);
            smoothAppBarLayout.syncOffset(0);
        }
    }
    return true;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 7 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project LookLook by xinghongfei.

the class TopNewsDescribeActivity method initData.

protected void initData() {
    id = getIntent().getStringExtra("docid");
    title = getIntent().getStringExtra("title");
    mTextView.setText(title);
    mImageUrl = getIntent().getStringExtra("image");
    scrollListener = new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (oldScrollY < 168) {
                mShot.setOffset(-oldScrollY);
                mTextView.setOffset(-oldScrollY);
            }
        }
    };
    Glide.with(this).load(mImageUrl).override(width, heigh).listener(glideLoadListener).centerCrop().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(mShot);
    mTopNewsDesPresenter = new TopNewsDesPresenterImpl(this);
    mNest.setOnScrollChangeListener(scrollListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
        mShot.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                mShot.getViewTreeObserver().removeOnPreDrawListener(this);
                startPostponedEnterTransition();
                return true;
            }
        });
    }
    mReturnHomeListener = new AnimUtils.TransitionListenerAdapter() {

        @Override
        public void onTransitionStart(Transition transition) {
            super.onTransitionStart(transition);
            // hide the fab as for some reason it jumps position??  TODO work out why
            mToolbar.animate().alpha(0f).setDuration(100).setInterpolator(new AccelerateInterpolator());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mShot.setElevation(1f);
                mToolbar.setElevation(0f);
            }
            mNest.animate().alpha(0f).setDuration(50).setInterpolator(new AccelerateInterpolator());
        }
    };
    mEnterTrasitionListener = new AnimUtils.TransitionListenerAdapter() {

        @Override
        public void onTransitionEnd(Transition transition) {
            super.onTransitionEnd(transition);
            //                    解决5.0 shara element bug
            ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 100).setDuration(100);
            valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    //                            mShot.setOffset((Integer) valueAnimator.getAnimatedValue() * 10);
                    mNest.smoothScrollTo((Integer) valueAnimator.getAnimatedValue() / 10, 0);
                }
            });
            valueAnimator.start();
        //                    mShot.setAlpha(0.5f);
        //                    mShot.animate().alpha(1f).setDuration(800L).start();
        }

        @Override
        public void onTransitionResume(Transition transition) {
            super.onTransitionResume(transition);
        }
    };
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ValueAnimator(android.animation.ValueAnimator) AnimUtils(com.looklook.xinghongfei.looklook.util.AnimUtils) Transition(android.transition.Transition) NestedScrollView(android.support.v4.widget.NestedScrollView) TopNewsDesPresenterImpl(com.looklook.xinghongfei.looklook.presenter.implPresenter.TopNewsDesPresenterImpl) ViewTreeObserver(android.view.ViewTreeObserver)

Example 8 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project easy by MehdiBenmesa.

the class Utils method scrollTo.

public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 9 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project bilibili-android-client by HotBitmapGG.

the class BangumiDetailsActivity method initToolBar.

@Override
public void initToolBar() {
    mToolbar.setTitle("番剧详情");
    setSupportActionBar(mToolbar);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    //设置Toolbar的透明度
    mToolbar.setBackgroundColor(Color.argb(0, 251, 114, 153));
    //设置StatusBar透明
    SystemBarHelper.immersiveStatusBar(this);
    SystemBarHelper.setPadding(this, mToolbar);
    //获取顶部image高度和toolbar高度
    float imageHeight = getResources().getDimension(R.dimen.bangumi_details_top_layout_height);
    float toolBarHeight = getResources().getDimension(R.dimen.action_bar_default_height);
    mNestedScrollView.setNestedScrollingEnabled(true);
    mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            //根据NestedScrollView滑动改变Toolbar的透明度
            float offsetY = toolBarHeight - imageHeight;
            //计算滑动距离的偏移量
            float offset = 1 - Math.max((offsetY - scrollY) / offsetY, 0f);
            float absOffset = Math.abs(offset);
            //如果滑动距离大于1就设置完全不透明度
            if (absOffset >= 1) {
                absOffset = 1;
            }
            mToolbar.setBackgroundColor(Color.argb((int) (absOffset * 255), 251, 114, 153));
        }
    });
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) ActionBar(android.support.v7.app.ActionBar) SuppressLint(android.annotation.SuppressLint)

Example 10 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project GeekNews by codeestX.

the class ZhihuDetailActivity method initEventAndData.

@Override
protected void initEventAndData() {
    setToolBar(viewToolbar, "");
    Intent intent = getIntent();
    id = intent.getExtras().getInt("id");
    isNotTransition = intent.getBooleanExtra("isNotTransition", false);
    mPresenter.queryLikeData(id);
    mPresenter.getDetailData(id);
    mPresenter.getExtraData(id);
    ivProgress.start();
    WebSettings settings = wvDetailContent.getSettings();
    if (SharedPreferenceUtil.getNoImageState()) {
        settings.setBlockNetworkImage(true);
    }
    if (SharedPreferenceUtil.getAutoCacheState()) {
        settings.setAppCacheEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        if (SystemUtil.isNetworkConnected()) {
            settings.setCacheMode(WebSettings.LOAD_DEFAULT);
        } else {
            settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
        }
    }
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    wvDetailContent.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    nsvScroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (scrollY - oldScrollY > 0 && isBottomShow) {
                //下移隐藏
                isBottomShow = false;
                llDetailBottom.animate().translationY(llDetailBottom.getHeight());
            } else if (scrollY - oldScrollY < 0 && !isBottomShow) {
                //上移出现
                isBottomShow = true;
                llDetailBottom.animate().translationY(0);
            }
        }
    });
    (getWindow().getSharedElementEnterTransition()).addListener(new Transition.TransitionListener() {

        @Override
        public void onTransitionStart(Transition transition) {
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            /**
                 * 测试发现部分手机(如红米note2)上加载图片会变形,没有达到centerCrop效果
                 * 查阅资料发现Glide配合SharedElementTransition是有坑的,需要在Transition动画结束后再加载图片
                 * https://github.com/TWiStErRob/glide-support/blob/master/src/glide3/java/com/bumptech/glide/supportapp/github/_847_shared_transition/DetailFragment.java
                 */
            isTransitionEnd = true;
            if (imgUrl != null) {
                isImageShow = true;
                ImageLoader.load(mContext, imgUrl, detailBarImage);
            }
        }

        @Override
        public void onTransitionCancel(Transition transition) {
        }

        @Override
        public void onTransitionPause(Transition transition) {
        }

        @Override
        public void onTransitionResume(Transition transition) {
        }
    });
}
Also used : WebSettings(com.tencent.smtt.sdk.WebSettings) Transition(android.transition.Transition) Intent(android.content.Intent) WebView(com.tencent.smtt.sdk.WebView) NestedScrollView(android.support.v4.widget.NestedScrollView) WebViewClient(com.tencent.smtt.sdk.WebViewClient)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)20 View (android.view.View)8 RecyclerView (android.support.v7.widget.RecyclerView)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 ViewGroup (android.view.ViewGroup)5 ViewTreeObserver (android.view.ViewTreeObserver)4 TextView (android.widget.TextView)4 AppBarLayout (android.support.design.widget.AppBarLayout)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 ViewPager (android.support.v4.view.ViewPager)3 Toolbar (android.support.v7.widget.Toolbar)3 Menu (android.view.Menu)3 MenuItem (android.view.MenuItem)3 ImageView (android.widget.ImageView)3 Test (org.junit.Test)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Nullable (android.support.annotation.Nullable)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2