Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue #53 , also did some refactoring to improve the readabilit…

…y of sticky code.
  • Loading branch information...
commit 0879d7e59f7f7b196315ff3e11f02e3de084d801 1 parent caa34e1
@emilsjolander authored
View
38 library/src/com/emilsjolander/components/stickylistheaders/StickyListHeadersListView.java
@@ -280,40 +280,34 @@ private void scrollChanged(int firstVisibleItem) {
final int childCount = getChildCount();
if (childCount != 0) {
+ WrapperView viewToWatch = null;
+ int watchingChildDistance = 99999;
- WrapperView viewToWatch = (WrapperView) super.getChildAt(0);
-
- int firstChildDistance;
- if (clippingToPadding) {
- firstChildDistance = Math
- .abs((viewToWatch.getTop() - getPaddingTop()));
- } else {
- firstChildDistance = Math.abs(viewToWatch.getTop());
- }
-
- int headerHeight = getHeaderHeight();
-
- for (int i = 1; i < childCount; i++) {
+ for (int i = 0; i < childCount; i++) {
WrapperView child = (WrapperView) super.getChildAt(i);
- int secondChildDistance;
+ int childDistance;
if (clippingToPadding) {
- secondChildDistance = Math
- .abs((child.getTop() - getPaddingTop())
- - headerHeight);
+ childDistance = child.getTop() - getPaddingTop();
} else {
- secondChildDistance = Math.abs(child.getTop()
- - headerHeight);
+ childDistance = child.getTop();
+ }
+
+ if(childDistance<0){
+ continue;
}
- if (!viewToWatch.hasHeader()
- || (child.hasHeader() && secondChildDistance < firstChildDistance)) {
+ if (viewToWatch == null || !viewToWatch.hasHeader()
+ || (child.hasHeader() && childDistance < watchingChildDistance)) {
viewToWatch = child;
+ watchingChildDistance = childDistance;
}
}
- if (viewToWatch.hasHeader()) {
+ int headerHeight = getHeaderHeight();
+ if (viewToWatch != null && viewToWatch.hasHeader()) {
+
if (firstVisibleItem == 0 && super.getChildAt(0).getTop() > 0
&& !clippingToPadding) {
headerBottomPosition = 0;
View
23 sample/res/layout/header.xml
@@ -1,14 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/header_bg"
- android:orientation="horizontal" >
+ android:layout_height="100dp"
+ android:background="#ffff0000"
+ android:gravity="bottom"
+ android:orientation="vertical" >
<TextView
android:id="@+id/text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textColor="@android:color/black"/>
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="left"
+ android:paddingLeft="4dp"
+ android:textColor="#ff33b5e5"
+ android:textSize="15sp"
+ android:textStyle="bold" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="2dp"
+ android:layout_marginTop="2dp"
+ android:background="#ff33b5e5" />
</LinearLayout>
Please sign in to comment.
Something went wrong with that request. Please try again.