@@ -47,7 +47,7 @@ class StickyScrollView @JvmOverloads constructor(
4747 mStickyScrollPresenter.recomputeFooterLocation(getFooterTop())
4848 }
4949 stickyHeaderView?.let {
50- mStickyScrollPresenter.recomputeHeaderLocation(it.top )
50+ mStickyScrollPresenter.recomputeHeaderLocation(getRelativeHeaderTop(it) )
5151 }
5252 }
5353
@@ -99,32 +99,42 @@ class StickyScrollView @JvmOverloads constructor(
9999 this .scrollViewListener = scrollViewListener
100100 }
101101
102- private fun initialiseHeader (){
103- mStickyScrollPresenter.initStickyHeader(stickyHeaderView?.top)
102+ private fun initialiseHeader () {
103+ stickyHeaderView?.let {
104+ mStickyScrollPresenter.initStickyHeader(getRelativeHeaderTop(it))
105+ }
104106 }
105107
106- private fun initialiseFooter (){
108+ private fun initialiseFooter () {
107109 mStickyScrollPresenter.initStickyFooter(
108110 stickyFooterView?.measuredHeight,
109111 getFooterTop()
110112 )
111113 }
112114
113- private fun getRelativeTop (myView : View ): Int {
115+ private fun getRelativeHeaderTop (myView : View ): Int {
116+ return if (myView.parent == = this ) {
117+ myView.top
118+ } else {
119+ myView.top + getRelativeHeaderTop(myView.parent as View )
120+ }
121+ }
122+
123+ private fun getRelativeFooterTop (myView : View ): Int {
114124 return if (myView.parent == = myView.rootView) {
115125 myView.top
116126 } else {
117- myView.top + getRelativeTop (myView.parent as View )
127+ myView.top + getRelativeFooterTop (myView.parent as View )
118128 }
119129 }
120130
121131 private fun getFooterTop (): Int {
122132 return stickyFooterView?.let {
123- return getRelativeTop (it) - it.topCutOutHeight()
133+ return getRelativeFooterTop (it) - it.topCutOutHeight()
124134 } ? : 0
125135 }
126136
127- private inner class StickyScrollPresentation : IStickyScrollPresentation {
137+ private inner class StickyScrollPresentation : IStickyScrollPresentation {
128138 override val currentScrollYPos: Int
129139 get() = scrollY
130140
@@ -143,6 +153,7 @@ class StickyScrollView @JvmOverloads constructor(
143153 stickyHeaderView?.let {
144154 it.translationY = translationY.toFloat()
145155 PropertySetter .setTranslationZ(it, 1f )
156+ PropertySetter .setTranslationZ(it.parent as View , 1f )
146157 }
147158 }
148159
@@ -183,4 +194,4 @@ class StickyScrollView @JvmOverloads constructor(
183194 private const val STATE_SUPER = " super_state"
184195 private const val STATE_NAV_BAR_HEIGHT = " nav_bar_height_state"
185196 }
186- }
197+ }
0 commit comments