ScrollView滑动监听显示标题栏
2017-12-21 09:34
344 查看
重写ScrollView: package com.example.ningac.mathom_a.myview; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ScrollView; /** * Created by Ning.A.C on 2017/12/17. */ public class MyScrollView extends ScrollView{ private ScrollViewListener scrollViewListener = null; public MyScrollView(Context context) { super(context); } public MyScrollView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onScrollChanged(int x, int y, int oldx, int oldy) { //x为当前滑动条的横坐标,y表示当前滑动条的纵坐标,oldx为前一次滑动的横坐标,oldy表示前一次滑动的纵坐标 super.onScrollChanged(x, y, oldx, oldy); if (scrollViewListener != null) { //在这里将方法暴露出去 scrollViewListener.onScrollChanged(this, x, y, oldx, oldy); } } //是否要其弹性滑动 @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { // 弹性滑动关键则是maxOverScrollX, 以及maxOverScrollY, // 一般默认值都是0,需要弹性时,更改其值即可 // 即就是,为零则不会发生弹性,不为零(>0,负数未测试)则会滑动到其值的位置 return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, 0, 0, isTouchEvent); } //接口 public interface ScrollViewListener { void onScrollChanged(View scrollView, int x, int y, int oldx, int oldy); } public void setScrollViewListener(ScrollViewListener listener) { scrollViewListener=listener; } }
设置标题栏:scrollView.setScrollViewListener(new MyScrollView.ScrollViewListener() {@Overridepublic void onScrollChanged(View scrollView, int x, int y, int oldx, int oldy) {if (isFirst) {isFirst = false;}titleAnim(oldy,y);}});public void titleAnim(int oldy,int y){Log.d("zzz",oldy+" "+y);if(y==0){found_title.setAlpha(0);}else{if (y <= 100) {float alpha =((float) y) / 100;found_title.setAlpha(alpha);if (alpha==0){found_title.setClickable(false);}else{found_title.setClickable(true);}}else {found_title.setAlpha(1);}}// }else{//// }// if (y < 200) {// float alpha = 1 - ((float) y) / 200;// found_title.setAlpha(alpha);// if (alpha==0)// {// found_title.setClickable(false);// }else// {// found_title.setClickable(true);// }// } else {// //下滑显示标题栏// if (oldy > y) {// found_title.setAlpha(1);// found_title.setClickable(true);// } else {// found_title.setAlpha(0);// found_title.setClickable(false);// }// }}
相关文章推荐
- Android中自定义ScrollView的滑动监听事件,并在滑动时渐变标题栏背景颜色
- 通过ImageView的点击监听事件来滑动ScrollView的滚动条,进而改变屏幕显示内容
- Android 监听 ScrollView 滑动到最底部,实现阅读协议,滑动到最低端显示已阅读按钮(2017版本)
- 滑动监听,当上拉时上面标题栏逐渐显示出来
- ListView+头部向上滑动标题栏渐显以及ScrollView向上滑动标题栏渐显
- Android中自定义ScrollView的滑动监听事件
- ScrollView水平滑动条选中条目的居中显示
- ScrollView滑动的监听
- 解决ScrollView嵌套RecyclerView 滑动卡顿和嵌套多个RecyclerView 显示不全的问题
- Android ScrollView嵌套HorizontalScrollView 滑动问题 ScrollView包括GridView显示问题
- 监听ScrollView上下滑动
- android 监听scrollview 滑动动作
- 解决ScrollView中嵌套Listview,Listview中嵌套Listview显示不完整和滑动冲突的问题
- ScrollView滑动实现标题栏透明度随之渐变
- scrollview添加自定义view的滑动显示问题
- 监听滑动到底部的ScrollView
- Android ScrollView滑动实现仿QQ空间标题栏渐变
- ScrollView滑动到底部的监听
- Android ScrollView的滑动监听
- 实现ScrollView滑动时标题栏的隐藏效果