啊啊啊,我又来更新了。java
哈哈哈,分享最近有趣小点。动画
最近在作详情页滑动渐变显示与淡入淡出效果,我也是费尽脑筋查了又查,搜了又搜。code
最后仍是用最原生的方式实现了,多了不说少了不唠,仔细阅读如下文字。get
note:接下来这个方法是获取view的原始有颜色,经过RGB计算将色值一点点调透明度。animation
private void setDetailTitleColor(int scrollY) { if (mDetailTitle == null) { return; } if (scrollY == 0) { mDetailTitle.setTextColor(Colo.White); } else { int color = mDetailTitle.getTextColors().getDefaultColor(); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int changeToColor = Color.argb((255 * (scrollY - 1)), r, g, b); mDetailTitle.setTextColor(changeToColor); } }
附赠:渐渐隐藏和渐渐显示的动画it
public static void fadeInVisible(@NonNull View view, float startAlpha, float endAlpha) { if (view.getVisibility() == View.VISIBLE) { return; } view.setVisibility(View.VISIBLE); Animation animation = new AlphaAnimation(startAlpha, endAlpha); animation.setDuration(500); view.startAnimation(animation); }public static void fadeOutGone(@NonNull View view, float startAlpha, float endAlpha) { if (view.getVisibility() == View.GONE) { return; } view.setVisibility(View.GONE); Animation animation = new AlphaAnimation(startAlpha, endAlpha); animation.setDuration(500); view.startAnimation(animation); }调用方式:io
//渐渐显示 fadeInVisible(mDetailTitle, 0f, 1f); //渐渐隐藏 fadeOutGone(mDetailTitle, 1f, 0f);