滑动ScrollView,改变搜索栏背景,透明

自定义View:

package com.example.jingdong.FirstPages;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ScrollView;

import com.example.jingdong.FirstPages.FirstPageSearchs.FirstPageSearch;
import com.youth.banner.Banner;

public class AlphaTitleScrollView extends ScrollView {
    public static final String TAG = "AlphaTitleScrollView";
    private int mSlop;
    private FirstPageSearch mytitleview;
    private Banner banner;

    public AlphaTitleScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public AlphaTitleScrollView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

    }

    public AlphaTitleScrollView(Context context) {
        this(context, null);
    }

    private void init(Context context) {
        // mSlop = ViewConfiguration.get(context).getScaledDoubleTapSlop();
        mSlop = 10;
        Log.i(TAG, mSlop + "");
    }
    //Activity中调用,获取了本自定义View的控件id,就可调用.
    public void setTitleAndHead(FirstPageSearch mytitleview,Banner banner) {
        this.mytitleview = mytitleview;  //搜索栏,头布局
        this.banner = banner;   //需要和搜索栏对比滑动高度的bannerbuju,这里最上边的布局是banner,别的也行
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        float headHeight = banner.getMeasuredHeight()
                - mytitleview.getMeasuredHeight();
        int alpha = (int) (((float) t / headHeight) * 255);
        if (alpha >= 255)
            alpha = 255;
        if (alpha <= mSlop)
            alpha = 0;
        mytitleview.setBackgroundColor(Color.argb(alpha, 0, 0, 0));

        super.onScrollChanged(l, t, oldl, oldt);
    }
}

sv.setTitleAndHead(fs,banner);  //自定义View里的方法
sv.setBackgroundColor(Color.argb(0, 1, 1, 1));  //初始化搜索栏背景颜色


关于自定义ScrollView自动滑动的问题,自布局焦点:

<com.bwie.dongchangqi.personaltailor.CustomViews.CustomScrollView
    android:id="@+id/found_scrollview_show"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"                         //-------加入-----------
        android:focusableInTouchMode="true"               //--------加入---------
        >
        <android.support.v7.widget.RecyclerView
            android:id="@+id/found_recyclerview_show"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</com.bwie.dongchangqi.personaltailor.CustomViews.CustomScrollView>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值