-
Notifications
You must be signed in to change notification settings - Fork 14
/
ShopPriceLayout.kt
66 lines (55 loc) · 2.03 KB
/
ShopPriceLayout.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.ziwenl.meituan_detail.ui.shop
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.ziwenl.meituan_detail.R
import com.ziwenl.meituan_detail.utils.dp
import com.ziwenl.meituan_detail.utils.stateRefresh
import com.ziwenl.meituan_detail.utils.stateSave
import com.ziwenl.meituan_detail.utils.statesChangeByAnimation
import kotlinx.android.synthetic.main.layout_shop_price.view.*
/**
* PackageName : com.ziwenl.meituan_detail.ui.shop
* Author : Ziwen Lan
* Date : 2020/11/19
* Time : 16:18
* Introduction : 店铺详情 -- 底部价格(满减神器、满减优惠、结算价格)
*/
class ShopPriceLayout : ConstraintLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
private fun animViews(): Array<View> = arrayOf(cl_main)
init {
LayoutInflater.from(context).inflate(R.layout.layout_shop_price, this)
}
private var firstLayout: Boolean = false
private var effected: Float = 0f
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
super.onWindowFocusChanged(hasWindowFocus)
if (!firstLayout) {
firstLayout = true
//记录 View 状态
cl_main.stateSave(R.id.viewStateStart).alpha(1F)
cl_main.stateSave(R.id.viewStateEnd).alpha(0F)
}
}
/**
* 根据业务需求动态计算变化高度区别
*/
fun effectByOffset(transY: Float) {
effected = when {
transY <= dp(140) -> 0F
transY > dp(140) && transY < dp(230) -> (transY - dp(140)) / dp(90)
else -> 1F
}
animViews().forEach { it.stateRefresh(R.id.viewStateStart, R.id.viewStateEnd, effected) }
}
private var mIsExpanded = false
}