android页面滑动时,顶部title背景渐变的实现

本文介绍了如何在Android中实现在ScrollView滑动时顶部标题背景颜色的渐变效果。通过重写ScrollView,添加滑动监听并在滑动过程中处理标题,以此达到淘宝商品详情页类似的交互体验。文章提供了布局文件和自定义ScrollView的实现代码,展示了如何根据滑动距离动态调整标题背景。
摘要由CSDN通过智能技术生成

在淘宝的商品详情页,我们会看到顶部的title背景颜色随着scrollView的上下滑动而渐变,这样的功能在我们应用中会经常用到,今天就来说一下我实现下这种功能方法,当然方法可能比较笨,看到博客的大牛,希望能得到你们的指点。

先晒几张效果图:

                            


首先先解释一下基本原理:我们的思路是重写ScrollView,实现ScrollView的滑动监听,在ScrollView滑动的过程中,对顶部Title做出相应的处理:

看一下title的布局文件:title.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/green"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/background_circle"
        android:padding="10dp"
        android:src="@drawable/icon_back" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/background_circle"
        android:padding="10dp"
        android:src="@drawable
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值