Skip to content

Commit

Permalink
Merge pull request #9489 from garymathews/TIMOB-25258_6_3_X
Browse files Browse the repository at this point in the history
[6_3_X][TIMOB-25258] Android: TableView bottom border extends past the last table row
  • Loading branch information
Lokesh Choudhary committed Oct 2, 2017
2 parents 8bf1ef9 + e91c92b commit 45308da
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.view.View.MeasureSpec;


/**
Expand All @@ -16,6 +18,8 @@
* Extends Google's "SwipeRefreshLayout" class by adding a new setSwipeRefreshEnabled() method.
* Allows the swipe-down feature to be disabled independently of the setEnabled() method that
* Google's implementation uses to disable this feature (along with touch support).
* <p>
* Also adds WRAP_CONTENT support for height. (Google's implementation does not support this.)
*/
public class TiSwipeRefreshLayout extends SwipeRefreshLayout
{
Expand Down Expand Up @@ -61,4 +65,56 @@ public void setSwipeRefreshEnabled(boolean value)
{
this.isSwipeRefreshEnabled = value;
}

/**
* Called when this view's measure() method gets called. Typically called by the parent view.
* Updates this view's width and height based on the given width and height constraints.
* <p>
* Given arguments' size and mode can be extracted via the Android "View.MeasureSpec" class.
* @param widthMeasureSpec Provides the parent's width constraints and size mode.
* @param heightMeasureSpec Provides the parent's height constraints and size mode.
*/
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
// If height mode not set to "exactly", then change height to match view's tallest child.
// Note: We need to do this since Google's "SwipeRefreshLayout" class ignores the
// WRAP_CONTENT setting and will fill the height of the parent view instead.
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode != MeasureSpec.EXACTLY) {
// Determine the min height needed to fit this view's tallest child view.
int minHeight = 0;
for (int index = getChildCount() - 1; index >= 0; index--) {
// Fetch the next child.
View child = getChildAt(index);
if (child == null) {
continue;
}

// Skip child views that are flagged as excluded from the layout.
if (child.getVisibility() == View.GONE) {
continue;
}

// Determine the height of the child.
child.measure(widthMeasureSpec, heightMeasureSpec);
int childHeight = child.getMeasuredHeight();
childHeight += child.getPaddingTop() + child.getPaddingBottom();

// Store the child's height if it's the tallest so far.
minHeight = Math.max(minHeight, childHeight);
}

// Make sure we're not below the suggested min height assigned to this view.
minHeight = Math.max(minHeight, getSuggestedMinimumHeight());

// Update this view's given height spec to match the tallest child view.
if (minHeight < MeasureSpec.getSize(heightMeasureSpec)) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(minHeight, heightMode);
}
}

// Update this view's measurements.
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

0 comments on commit 45308da

Please sign in to comment.