//实现自定义ScrollView 滑动改变背景颜色
首先要自定义一个ScrollView
切记一定要能滑动,也就是说ScrollView 里面的东西要多,不然不好使.
自定义
public class JiChengShi extends ScrollView {
public JiChengShi(Context context) {
this(context,null);
}
public JiChengShi(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public JiChengShi(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public interface ScrollViewListener{
void onScrollChanged(JiChengShi jiChengShi,int l, int t, int oldl, int oldt);
}
private ScrollViewListener mscrollViewListener;
//向外提供一个方法
public void setOnScrollChange(ScrollViewListener scrollViewListener){
mscrollViewListener=scrollViewListener;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if(mscrollViewListener!=null){
mscrollViewListener.onScrollChanged(this,l, t, oldl, oldt);
}
}
}
//布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="match_parent">
<com.bwie.jd_2.Zidingyi.JiChengShi
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.stx.xhb.xbanner.XBanner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="250px"
app:AutoPlayTime="2000"
app:pointNormal="@drawable/dot_no_select"
app:pointSelect="@drawable/dot_select"
app:pointsContainerBackground="#44AAAAAA"
app:pointsPosition="CENTER"
app:tipTextColor="#F