Android之scrollview滑动使导航栏渐变背景色
来源:互联网 发布:centos 安装gcc g 编辑:程序博客网 时间:2024/04/27 19:42
一:先来效果图:
-----------------转载请注明出处:http://blog.csdn.net/android_cll
第一二张效果图是用红线标注,第三张为黑线,三张为不同滑动距离的效果图,不想弄GIF的,凑合看吧、
二:实现步骤:
1.xml实现,在你的布局加上scrollview,也可以自定义scrollview,都有注释,就不用解释太多了、
<com.zjtd.bzcommunity.lib.myScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </com.zjtd.bzcommunity.lib.myScrollView>
2.代码实现、
private myScrollView mScrollView; // 整体ScrollViewprivate int fadingHeight = 600; // 当ScrollView滑动到什么位置时渐变消失(根据需要进行调整)private Drawable drawable; // 顶部渐变布局需设置的Drawableprivate RelativeLayout layout_top_search;//导航栏private static final int START_ALPHA = 0;//scrollview滑动开始位置private static final int END_ALPHA = 255;//scrollview滑动结束位置
mScrollView = (myScrollView) view.findViewById(R.id.scrollView);drawable = getResources().getDrawable(R.color.dhlbg);drawable.setAlpha(START_ALPHA);layout_top_search.setBackgroundDrawable(drawable);//调用方法mScrollView.setOnScrollChangedListener(scrollChangedListener);
/** * ScrollView的滚动监听 */ private myScrollView.OnScrollChangedListener scrollChangedListener = new myScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int x, int y, int oldx, int oldy) { if (y > fadingHeight) { y = fadingHeight; // 当滑动到指定位置之后设置颜色为纯色,之前的话要渐变---实现下面的公式即可// relativela_id.setBackgroundColor(Color.WHITE); } else if (y < 0) { y = 0; } else {// relativela_id.setBackgroundColor(0x99FFFFFF); } drawable.setAlpha(y * (END_ALPHA - START_ALPHA) / fadingHeight + START_ALPHA); } };
---------------------------差不多就是这样子了,不喜勿喷、
14 0
- Android之scrollview滑动使导航栏渐变背景色
- Android 标题栏滑动渐变背景色
- android——顶部导航栏滑动变换背景色
- Android 特效库 - 实现滑动ViewPager渐变背景色
- android控件背景色渐变
- Android UI 背景色渐变
- android 设置渐变背景色
- Android之通过shape.xml制作渐变背景色
- 导航栏背景色改变
- 浏览器兼容性之背景色渐变
- Html中背景色之颜色渐变
- Android背景色渐变(左上->右下)
- ViewPager引导页根据滑动渐变背景色
- Android修改状态栏和导航栏背景色
- css 背景色渐变
- 绘制渐变背景色
- 背景色渐变
- 设置渐变背景色
- 关于ImageLoader图片缓存
- #1473 : 小Ho的强迫症
- android中的IPC机制
- [Error 13] Permission denied
- JavaScript中的事件
- Android之scrollview滑动使导航栏渐变背景色
- SpringBoot +SpringCloud微服务示例,整合FreeMaker,AngularJS
- 用select改进回射客户-服务器模型
- 从0开始学习Android开发2017,3
- 二分小结
- 培训行业这一年读书笔记
- 2017-03-05 CentOS中配置守护服务(Supervisor)监听dotnet core web程序的运行
- solr相关配置翻译
- 一般图最大匹配-带花树-带注释模板