实现头部透明度变化

news/2024/7/16 9:36:26

首先布局:布局很简单

<?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);
    }
};


http://www.niftyadmin.cn/n/3649128.html

相关文章

[Perl]测试程序时用Perl真是太方便了

测试自己的业务数据远程传送服务&#xff0c;需要一个能模拟对方Socket的服务&#xff0c;这时候就显出Perl的便利了。一分钟搞定。代码如下&#xff0c;其实也是从CPAN那里拿来的&#xff1a;###################################################################### 工程项目…

如何使用Node.js抓取网站

介绍 (Introduction) Web scraping is the technique of extracting data from websites. This data can further be stored in a database or any other storage system for analysis or other uses. While extracting data from websites can be done manually, web scraping…

[USTC]中科大备忘录

中科大的罪行之一&#xff1a; 居然到现在还不衰落。 世界学术排名最高的7所中国大陆大学&#xff1a;1 清华大学 248名 75.0分&#xff08;Tsing Hua Univ&#xff09; 2 北京大学 287名 66.9分&#xff08;Peking Univ&#xff09; 3 中国科大 312名 62.1分&#xff08;Univ …

如何在DigitalOcean Kubernetes上设置Eclipse Theia Cloud IDE平台

介绍 (Introduction) With developer tools moving to the cloud, creation and adoption of cloud IDE (Integrated Development Environment) platforms is growing. Cloud IDEs are accessible from every type of modern device through web browsers, and they offer nume…

Android中View绘制不同状态背景图片原理以及StateListDrawable使用详解

1、View的几种不同状态属性2、如何根据不同状态去切换我们的背景图片。开篇介绍&#xff1a;android背景选择器selector用法汇总对Android开发有经验的同学&#xff0c;对 <selector>节点的使用一定很熟悉&#xff0c;该节点的作用就是定义一组状态资源图片&#xff0c;使…

django中的app_如何在Django中构建Weather App

django中的app介绍 (Introduction) In this article we’ll build a simple Django app that displays the current weather for various cities. To get the current weather data, we’ll use the Open Weather Map API. 在本文中&#xff0c;我们将构建一个简单的Django应用…

酷炫轮播广告

一、广告轮播条的简介 广告轮播条在HTML网页设计以及APP界面设计中非常常见&#xff0c;如下图所示。在Android中&#xff0c;实现的方式可以是自定义ViewPager来实现&#xff0c;但是我们程序员中流传的一句名言&#xff0c;“不要重复造轮子”。因此我们也可以通过网上已经有…

android View 详解

一、View 的概述 android.View.View(即View)类是以矩形的方式显示在屏幕上&#xff0c;View是用户界面控件的基础。View的继承层次关系如下图&#xff1a; 可以看到所有的界面控件都是View的子类。简单证实一下&#xff0c;每当你用findViewByIds(R.id.xx)时总要将其强转&#…