NotifyingScrollView
package com.app.lx.actionbar;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
public class NotifyingScrollView extends ScrollView{
/**
* @author Cyril Mottier
*/
public interface OnScrollChangedListener {
void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);
}
private OnScrollChangedListener mOnScrollChangedListener;
public NotifyingScrollView(Context context) {
super(context);
}
public NotifyingScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
public void setOnScrollChangedListener(OnScrollChangedListener listener) {
mOnScrollChangedListener = listener;
}
}
调用
nsv_store.setOnScrollChangedListener(new OnScrollChangedListener() {
@SuppressLint("NewApi")
@Override
public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
// 当店铺整个界面滚动的时候,改变相对应的操作
if (ab_top == null) {
return;
}
if(t<0){
return;
}
int lHeight = ab_top.getHeight();
if (t <= lHeight) {
int progress = (int) (new Float(t) / new Float(lHeight) * 255);
ab_top.getBackground().setAlpha(progress);
} else {
ab_top.getBackground().setAlpha(255);
}
}
});