Search in sources :

Example 1 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 2 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 3 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 4 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project SmoothRefreshLayout by dkzwm.

the class HorizontalBoundaryUtil method isVerticalView.

private static boolean isVerticalView(View view) {
    if (view instanceof AbsListView || view instanceof ScrollView || view instanceof NestedScrollView || view instanceof WebView) {
        return true;
    }
    try {
        if (view instanceof RecyclerView) {
            RecyclerView recyclerView = (RecyclerView) view;
            RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
            if (manager != null) {
                if (manager instanceof LinearLayoutManager) {
                    LinearLayoutManager linearManager = ((LinearLayoutManager) manager);
                    if (linearManager.getOrientation() == LinearLayoutManager.VERTICAL)
                        return true;
                } else if (manager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) manager;
                    if (gridLayoutManager.getOrientation() == StaggeredGridLayoutManager.VERTICAL)
                        return true;
                }
            }
        }
    } catch (NoClassDefFoundError e) {
        e.printStackTrace();
    }
    return false;
}
Also used : ScrollView(android.widget.ScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView) WebView(android.webkit.WebView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 5 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project SmoothRefreshLayout by dkzwm.

the class ScrollCompat method scrollCompat.

public static boolean scrollCompat(View view, float deltaY) {
    if (view != null) {
        if (view instanceof AbsListView) {
            final AbsListView listView = (AbsListView) view;
            if (Build.VERSION.SDK_INT >= 19) {
                listView.scrollListBy((int) deltaY);
                return true;
            } else {
                try {
                    @SuppressLint("PrivateApi") Method method = AbsListView.class.getDeclaredMethod("trackMotionScroll", int.class, int.class);
                    if (method != null) {
                        method.setAccessible(true);
                        method.invoke(listView, -(int) deltaY, -(int) deltaY);
                    }
                } catch (Exception e) {
                    return false;
                }
            }
            return true;
        } else if ((view instanceof WebView) || (view instanceof ScrollView) || (view instanceof NestedScrollView)) {
            view.scrollBy(0, (int) deltaY);
        } else {
            try {
                if (view instanceof RecyclerView) {
                    view.scrollBy(0, (int) deltaY);
                    return true;
                }
            } catch (NoClassDefFoundError e) {
            // ignore exception
            }
        }
    }
    return false;
}
Also used : ScrollView(android.widget.ScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) RecyclerView(android.support.v7.widget.RecyclerView) Method(java.lang.reflect.Method) WebView(android.webkit.WebView) NestedScrollView(android.support.v4.widget.NestedScrollView)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)42 View (android.view.View)24 RecyclerView (android.support.v7.widget.RecyclerView)15 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)9 AppBarLayout (android.support.design.widget.AppBarLayout)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)6 Toolbar (android.support.v7.widget.Toolbar)6 AbsListView (android.widget.AbsListView)6 ImageView (android.widget.ImageView)6 ScrollView (android.widget.ScrollView)6 ViewTreeObserver (android.view.ViewTreeObserver)5 SuppressLint (android.annotation.SuppressLint)4 ViewPager (android.support.v4.view.ViewPager)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3