|
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; |
@@ -110,15 +111,25 @@ public void initHeaderBounds(Rect bounds, RecyclerView recyclerView, View header |
110 | 111 | private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) { |
111 | 112 | int translationX, translationY; |
112 | 113 | mDimensionCalculator.initMargins(mTempRect1, header); |
| 114 | + |
| 115 | + ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams(); |
| 116 | + int leftMargin = 0; |
| 117 | + int topMargin = 0; |
| 118 | + if (layoutParams instanceof ViewGroup.MarginLayoutParams) { |
| 119 | + ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams; |
| 120 | + leftMargin = marginLayoutParams.leftMargin; |
| 121 | + topMargin = marginLayoutParams.topMargin; |
| 122 | + } |
| 123 | + |
113 | 124 | if (orientation == LinearLayoutManager.VERTICAL) { |
114 | | - translationX = firstView.getLeft() + mTempRect1.left; |
| 125 | + translationX = firstView.getLeft() - leftMargin + mTempRect1.left; |
115 | 126 | translationY = Math.max( |
116 | | - firstView.getTop() - header.getHeight() - mTempRect1.bottom, |
| 127 | + firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom, |
117 | 128 | getListTop(recyclerView) + mTempRect1.top); |
118 | 129 | } else { |
119 | | - translationY = firstView.getTop() + mTempRect1.top; |
| 130 | + translationY = firstView.getTop() - topMargin + mTempRect1.top; |
120 | 131 | translationX = Math.max( |
121 | | - firstView.getLeft() - header.getWidth() - mTempRect1.right, |
| 132 | + firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right, |
122 | 133 | getListLeft(recyclerView) + mTempRect1.left); |
123 | 134 | } |
124 | 135 |
|
|
0 commit comments