越来越多的应用用到这种效果,自己动手写了写,希望和大家互相交流学习,不足之处还请不吝赐教。闲话不多,先上图:
原理是根据ListView当前滑动的高度和一个固定的高度值(需要在此时设置TitleBarView的alpha值为1)相除,得到一个alpha值,来动态设置TitleBar的透明度。
布局文件如下:
<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" >
<ListView
android:id="@+id/mlistview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f2f2f2"
android:cacheColorHint="#00000000"/>
<LinearLayout
android:id="@+id/layout_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" >
<TextView
android:layout_width="match_parent"