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));
}
});
}
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);
}
};
}
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);
}
}
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;
}
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;
}
Aggregations