在淘宝的商品详情页,我们会看到顶部的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