改了下引导页 新需求在引导页滑动时滑动上方标题 并且根据滑动渐变背景图片透明度 其实渐变图片和颜色是一样的 说下大概的思路 viewPager控制滑动 把需要滑动得部分放在viewPager中 而渐变背景 直接已RelativeLayout 放在viewPager上面 重点就是背景渐变得控制
在viewPager得监听方法里
//当页面在滑动的时候会调用此方法,在滑动被停止之前,此方法回一直被调用。 @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (positionOffset == 0 && position > 0) {//避免一页结束时,细微的闪移 return; } //arg0 :当前页面,及你点击滑动的页面 // arg1:当前页面偏移的百分比 // arg2:当前页面偏移的像素位置 switch (position) { case -1: case 0: one_to_two.setVisibility(View.VISIBLE); one_to_two.setAlpha(1f - positionOffset); two_to_three.setVisibility(View.VISIBLE); two_to_three.setAlpha(positionOffset); three_to_one.setVisibility(View.VISIBLE); three_to_one.setAlpha(0f); break; case 1: one_to_two.setVisibility(View.VISIBLE); two_to_three.setVisibility(View.VISIBLE); three_to_one.setVisibility(View.VISIBLE); if (positionOffset > 0) { two_to_three.setAlpha(1 - positionOffset); three_to_one.setAlpha(positionOffset); one_to_two.setAlpha(0f); } else { one_to_two.setAlpha(1 + positionOffset); two_to_three.setAlpha(0 - positionOffset); } break; case 2: one_to_two.setVisibility(View.VISIBLE); two_to_three.setVisibility(View.VISIBLE); three_to_one.setVisibility(View.VISIBLE); two_to_three.setAlpha(positionOffset); one_to_two.setAlpha(0f); break; } }
就行了 简单得一个透明度得设置 不是太复杂