|
4 | 4 | import android.support.v7.widget.LinearLayoutManager; |
5 | 5 | import android.support.v7.widget.RecyclerView; |
6 | 6 | import android.view.View; |
| 7 | +import android.view.ViewGroup; |
7 | 8 | import android.widget.LinearLayout; |
8 | 9 |
|
9 | 10 | import com.timehop.stickyheadersrecyclerview.caching.HeaderProvider; |
@@ -126,16 +127,26 @@ public void initHeaderBounds(Rect bounds, RecyclerView recyclerView, View header |
126 | 127 | private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation, boolean enableStickyHeader) { |
127 | 128 | int translationX, translationY; |
128 | 129 | mDimensionCalculator.initMargins(mTempRect1, header); |
| 130 | + |
| 131 | + ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams(); |
| 132 | + int leftMargin = 0; |
| 133 | + int topMargin = 0; |
| 134 | + if (layoutParams instanceof ViewGroup.MarginLayoutParams) { |
| 135 | + ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams; |
| 136 | + leftMargin = marginLayoutParams.leftMargin; |
| 137 | + topMargin = marginLayoutParams.topMargin; |
| 138 | + } |
| 139 | + |
129 | 140 | if (orientation == LinearLayoutManager.VERTICAL) { |
130 | | - translationX = firstView.getLeft() + mTempRect1.left; |
| 141 | + translationX = firstView.getLeft() - leftMargin + mTempRect1.left; |
131 | 142 | translationY = enableStickyHeader ? |
132 | | - Math.max(firstView.getTop() - header.getHeight() - mTempRect1.bottom, getListTop(recyclerView) + mTempRect1.top) : |
133 | | - firstView.getTop() - header.getHeight() - mTempRect1.bottom; |
| 143 | + Math.max(firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom, getListTop(recyclerView) + mTempRect1.top) : |
| 144 | + firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom; |
134 | 145 | } else { |
135 | | - translationY = firstView.getTop() + mTempRect1.top; |
| 146 | + translationY = firstView.getTop() - topMargin + mTempRect1.top; |
136 | 147 | translationX = enableStickyHeader ? |
137 | | - Math.max(firstView.getLeft() - header.getWidth() - mTempRect1.right, getListLeft(recyclerView) + mTempRect1.left) : |
138 | | - firstView.getLeft() - header.getWidth() - mTempRect1.right; |
| 148 | + Math.max(firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right, getListLeft(recyclerView) + mTempRect1.left) : |
| 149 | + firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right; |
139 | 150 | } |
140 | 151 |
|
141 | 152 | headerMargins.set(translationX, translationY, translationX + header.getWidth(), |
|
0 commit comments