diff --git a/.idea/misc.xml b/.idea/misc.xml
index f8a7968..239eb59 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java b/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java
index f0af835..112ed73 100644
--- a/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java
+++ b/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java
@@ -63,7 +63,10 @@ public class SlidingDrawer extends LinearLayout {
private final int touchSlop = viewConfiguration.getScaledTouchSlop();
// view that will slide
- private View slidableView;
+ private @NonNull View slidableView;
+
+ // view that won't slide
+ private @NonNull View nonSlidableView;
// current slide value, between 1.0 and 0.0 (1.0 = EXPANDED, 0.0 = COLLAPSED)
private float currentSlide;
@@ -75,7 +78,7 @@ public class SlidingDrawer extends LinearLayout {
private final static int mCoveredFadeColor = 0x99000000;
// max value by which sliding view can slide.
- private int maxSlide;
+// private int maxSlide;
private final int minSlide = 0;
// duration of the slide in milliseconds, when executed automatically
@@ -190,6 +193,8 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
public boolean onTouchEvent(MotionEvent event) {
float eventY = event.getY();
+ final float maxSlide = nonSlidableView.getHeight();
+
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
// complete the slide if it's not completed yet.
@@ -217,6 +222,8 @@ else if(eventY + dY < minSlide)
}
private void completeSlide(float currentSlide, @SlidingDirection int direction) {
+ final float maxSlide = nonSlidableView.getHeight();
+
float finalY = -1;
switch (direction) {
@@ -248,6 +255,8 @@ else if(currentSlide == 0)
}
private float normalizeSlide(float currentY) {
+ final float maxSlide = nonSlidableView.getHeight();
+
// currentSlide_Normalized : x = 1 : maxSliding
return Math.abs(currentY - maxSlide) / maxSlide;
}
@@ -257,6 +266,8 @@ private float normalizeSlide(float currentY) {
* @param newPositionNormalized new view position, normalized
*/
private void updateSliding(float newPositionNormalized) {
+ final float maxSlide = nonSlidableView.getHeight();
+
currentSlide = newPositionNormalized;
state = currentSlide == 1 ? EXPANDED : currentSlide == 0 ? COLLAPSED : SLIDING;
@@ -318,7 +329,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
private void initSlidingChild() {
slidableView = findViewById(R.id.slidable_view);
- maxSlide = findViewById(R.id.non_slidable_view).getHeight();
+ nonSlidableView = findViewById(R.id.non_slidable_view);
// the collapsed view is the view shown when the slidableView is collapsed.
// it's important to add padding to its bottom, otherwise some content will be offscreen-
@@ -332,10 +343,12 @@ private void initSlidingChild() {
* @param root the view that needs padding
*/
private void addPadding(View root) {
+ final float maxSlide = nonSlidableView.getHeight();
+
int top = root.getPaddingTop();
int left = root.getPaddingLeft();
int right = root.getPaddingRight();
- int bottom = maxSlide;
+ int bottom = (int) maxSlide;
root.setPadding(left, top, right, bottom);
}