先来观察完整的动画效果
分析:每个child都可以设置自己的属性动画 根据滑动出自身的高度比例来进行开发者设置的属性动画(平移 渐变 缩放 透明度...)既然是动画框架封装 肯定是希望开发者用的更爽,代码简洁 意图清晰。
首先设定好自定义的属性参数
<declare-styleable name="DiscrollView_LayoutParams">
<attr name="discrollve_alpha" format="boolean"/>
<attr name="discrollve_scaleX" format="boolean"/>
<attr name="discrollve_scaleY" format="boolean"/>
<attr name="discrollve_fromBgColor" format="color"/>
<attr name="discrollve_toBgColor" format="color"/>
<attr name="discrollve_translation">
<flag name="fromTop" value="0x01" />
<flag name="fromBottom" value="0x02" />
<flag name="fromLeft" value="0x04" />
<flag name="fromRight" value="0x08" />
</attr>
</declare-styleable>
解析为什么discrollve_translation 各个参数0x01 0x02 0x04 0x08
0x01 0000 0000 0000 0001 fromTop
0x02 0000 0000 0000 0010 fromBottom
0x04 0000 0000 0000 0100 fromLeft
0x08 0000 0000 0000 1000 fromRight
这样设置的目的 因为这个平移可以同时多个方向移动 比如我们希望他 左上方向移动 就可以这样设置
app:discrollve_translation = "fromTop|fromLeft"
既 它们的值 0000 0000 0000 0101 将来我们判断的时候 可以这样判断
比如判断是否设置了fromTop 就拿这个值 0101 & 0001fromTop = 0001 如果得出来的值等于fromTop就说明有设置这个值
我们希望开发者用这个属性动画框架的时候 只需要对对应的child设置相应属性参数 将来运行的时候就会执行相应的属性动画
理想开发者在布局文件设定即可
<com.twy.mywearview.MyScrollView xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:discrollve="http://schemas.android.com/apk/res-auto">
<com.twy.mywearview.MyLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="600dp"
android:src="@mipmap/tb_bg"
android:scaleType="centerCrop"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#007788"
android:textColor="@android:color/black"
android:textSize="25sp"
android:padding="25dp"
android:gravity="center"
android:fontFamily="serif"
android:text="带上您的行李箱,准备shopping!"
discrollve:discrollve_alpha="true"
tools:ignore="MissingPrefix" />
<ImageView
android:layout_width="200dp"
android:layout_height="120dp"
android:layout_gravity="top|right"
discrollve:discrollve_translation="fromLeft|fromBottom"
discrollve:discrollve_alpha="true"
android:src="@mipmap/baggage"
tools:ignore="MissingPrefix" />
<TextView