YoKeyword/Fragmentation · error · IllegalArgumentException
Threshold value should be between 0 and 1.0
Error message
Threshold value should be between 0 and 1.0
What it means
setScrollThresHold sets the fraction of the swipe distance required to trigger a swipe-back finish. It is annotated @FloatRange(0.0, 1.0) and explicitly rejects values >= 1.0f or <= 0 with an IllegalArgumentException, since the threshold must be an exclusive fraction.
Solutions
- Pass an exclusive fraction between 0 and 1.0, e.g. 0.5f.
- Convert integer percentages: threshold = percent / 100f, clamped to (0, 1).
Example fix
// before swipeBackLayout.setScrollThresHold(50); // after swipeBackLayout.setScrollThresHold(0.5f);
Defensive patterns
Strategy: validation
Validate before calling
float t = 0.5f; if (t > 0f && t < 1.0f) swipeBackLayout.setScrollThresHold(t);
Try / catch
try {
swipeBackLayout.setScrollThresHold(threshold);
} catch (IllegalArgumentException e) {
// fall back to default threshold
} Prevention
- Use floats strictly between 0 and 1.0 (e.g. 0.5f).
- Convert percentages with percent / 100f.
- Remember 0 and 1.0 are both invalid (exclusive bounds).
When it happens
Trigger: Calling swipeBackLayout.setScrollThresHold(0), setScrollThresHold(1), or any negative value / value above 1.
Common situations: Passing a percentage as whole numbers (e.g. 50 instead of 0.5); mistakenly using 1.0 meaning 'always finish' when 1.0 is invalid; porting config values from dp/px-based libraries.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Must extends FragmentActivity/AppCompatActivity and…
- Must extends FragmentActivity/AppCompatActivity
- Must extends Fragment
- not attach!
- must impl ISupportActivity!
AI-assisted analysis of YoKeyword/Fragmentation@0394930a3e (2026-09-10).
Data as JSON: /api/errors/efcec352f7e1af41.
Report an issue: GitHub.
Appendix: source
Thrown at fragmentation_swipeback/src/main/java/me/yokeyword/fragmentation/SwipeBackLayout.java:163
/**
* 滑动中,上一个页面View的阴影透明度
*
* @param alpha 0.0f:无阴影, 1.0f:较重的阴影, 默认:0.5f
*/
public void setSwipeAlpha(@FloatRange(from = 0.0f, to = 1.0f) float alpha) {
this.mSwipeAlpha = alpha;
}
/**
* Set scroll threshold, we will close the activity, when scrollPercent over
* this value
*
* @param threshold
*/
public void setScrollThresHold(@FloatRange(from = 0.0f, to = 1.0f) float threshold) {
if (threshold >= 1.0f || threshold <= 0) {
throw new IllegalArgumentException("Threshold value should be between 0 and 1.0");
}
mScrollFinishThreshold = threshold;
}
public void setParallaxOffset(float offset) {
this.mParallaxOffset = offset;
}
/**
* Enable edge tracking for the selected edges of the parent view.
* The callback's {@link ViewDragHelper.Callback#onEdgeTouched(int, int)} and
* {@link ViewDragHelper.Callback#onEdgeDragStarted(int, int)} methods will only be invoked
* for edges for which edge tracking has been enabled.
*
* @param orientation Combination of edge flags describing the edges to watch
* @see #EDGE_LEFT
* @see #EDGE_RIGHT
*/View on GitHub (pinned to 0394930a3e)