您的位置:首页 > 其它

ScrollView 透明 Actionbar

2015-12-10 15:31 351 查看
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);
}
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: