实现头部透明度变化

首先布局:布局很简单

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        android:id="@+id/ll_title_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#553190E8"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/ll_title_search"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="30dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"

                android:orientation="horizontal">

                <TextView
                    android:id="@+id/home_tv_address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="5dip"
                    android:layout_weight="1"
                    android:singleLine="true"
                    android:text="安徽合肥市经济开发区"

                    android:textColor="#FFF" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"

                    android:layout_marginRight="5dip"
                    android:src="@mipmap/home_address_drop_down" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="12dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="12dp"
                android:layout_weight="3"
                android:background="@drawable/home_search_text_background">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="10dip"
                    android:layout_weight="1"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="15dp"
                        android:layout_height="15dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="4dp"
                        android:src="@mipmap/home_search" />

                    <TextView

                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:text="输入商家、商品名称"
                        android:textColor="#FFF"
                        android:textSize="12sp" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>


    </LinearLayout>
</RelativeLayout>
二、当向下时改变头部透明度变化

private int sumY = 0;
private float duration = 150;//0-150之间透明度变化
private ArgbEvaluator evaluator=new ArgbEvaluator();
private RecyclerView.OnScrollListener listener = new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        sumY+=dy;
        int bgColor=0x553190E8;
        if(sumY<0){
            bgColor=0x553190E8;
        }else if(sumY>150){
            bgColor=0xFF3190E8;
        }else{
         bgColor= (int) evaluator.evaluate(sumY/duration,0x553190E8,0xFF3190E8);
        }
        llTitleContainer.setBackgroundColor(bgColor);
    }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值