标题渐变

public class ObservableScrollView extends ScrollView {

    public interface ScrollViewListener {

        void onScrollChanged(ObservableScrollView scrollView, int x, int y,
                             int oldx, int oldy);
    }
    private ScrollViewListener scrollViewListener = null;

    public ObservableScrollView(Context context) {
        super(context);
    }

    public ObservableScrollView(Context context, AttributeSet attrs,
                                int defStyle) {
        super(context, attrs, defStyle);
    }

    public ObservableScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setScrollViewListener(ScrollViewListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }
    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy) {
        super.onScrollChanged(x, y, oldx, oldy);
        if (scrollViewListener != null) {
            scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
        }
    }
}
 

//ScrollView

<com.example.dell.wy_one.view.custom.ObservableScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:layout_below="@id/tuijian"
            android:layout_marginLeft="16pt"
            android:id="@+id/choiceness_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="65pt"
            >

        </android.support.v7.widget.RecyclerView>

    </RelativeLayout>
</com.example.dell.wy_one.view.custom.ObservableScrollView>

//标题

<RelativeLayout
    android:id="@+id/line"
    android:layout_width="match_parent"
    android:layout_height="135pt">
    <TextView
        android:id="@+id/jingxuan"
        android:layout_width="match_parent"
        android:layout_height="82pt"
        android:textSize="32pt"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        />
</RelativeLayout>


@BindView(R.id.line)
RelativeLayout line;
@BindView(R.id.scrollView)
ObservableScrollView scrollView;
private int imageHeight = 500; //设置渐变高度,一般为导航图片高度,自己控制

//搜索框在布局最上面
        line.bringToFront();
//滑动监听
        scrollView.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {
            @Override
            public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
                if (y <= 0) {
                    line.setBackgroundColor(Color.argb((int) 0, 2, 255, 37));
                    jingxuan.setTextColor(Color.argb((int) 0, 255, 255, 255));
                    jingxuan.setText("精选");
                    //AGB由相关工具获得,或者美工提供
                } else if (y > 0 && y <= imageHeight) {
                    float scale = (float) y / imageHeight;
                    float alpha = (255 * scale);
// 只是layout背景透明
                    line.setBackgroundColor(Color.argb((int) alpha, 2, 255, 37));
                    jingxuan.setTextColor(Color.argb((int) alpha, 255, 255, 255));
                } else {
                    line.setBackgroundColor(Color.argb((int) 255, 2, 255, 37));
                    jingxuan.setTextColor(Color.argb((int) 255, 255, 255, 255));
                    jingxuan.setText("精选");
                }
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值