securesmartcam / app / src / main / java / org / witness / obscuracam / ui / ScrollViewBehaviorFix.java @ 41590feb
History | View | Annotate | Download (1.61 KB)
| 1 |
package org.witness.obscuracam.ui; |
|---|---|
| 2 |
|
| 3 |
import android.content.Context; |
| 4 |
import android.support.design.widget.AppBarLayout; |
| 5 |
import android.support.design.widget.CoordinatorLayout; |
| 6 |
import android.util.AttributeSet; |
| 7 |
import android.view.View; |
| 8 |
|
| 9 |
// This behavior fixes the problem that the view is not pinned to the bottom of the coordinator layout
|
| 10 |
// Fix for this: https://code.google.com/p/android/issues/detail?id=177195
|
| 11 |
//
|
| 12 |
public class ScrollViewBehaviorFix extends AppBarLayout.ScrollingViewBehavior { |
| 13 |
|
| 14 |
private AppBarLayout appBarLayout;
|
| 15 |
|
| 16 |
public ScrollViewBehaviorFix() {
|
| 17 |
super();
|
| 18 |
} |
| 19 |
|
| 20 |
public ScrollViewBehaviorFix(Context context, AttributeSet attrs) { |
| 21 |
super(context, attrs);
|
| 22 |
} |
| 23 |
|
| 24 |
@Override
|
| 25 |
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { |
| 26 |
|
| 27 |
if (appBarLayout == null) { |
| 28 |
appBarLayout = (AppBarLayout) dependency; |
| 29 |
} |
| 30 |
|
| 31 |
final boolean result = super.onDependentViewChanged(parent, child, dependency); |
| 32 |
|
| 33 |
int height = child.getHeight();
|
| 34 |
int newHeight = parent.getHeight() - dependency.getBottom();
|
| 35 |
int bottomPadding = height - newHeight;
|
| 36 |
|
| 37 |
//final int bottomPadding = calculateBottomPadding(appBarLayout);
|
| 38 |
final boolean paddingChanged = bottomPadding != child.getPaddingBottom(); |
| 39 |
if (paddingChanged) {
|
| 40 |
child.setPadding( |
| 41 |
child.getPaddingLeft(), |
| 42 |
child.getPaddingTop(), |
| 43 |
child.getPaddingRight(), |
| 44 |
bottomPadding); |
| 45 |
child.requestLayout(); |
| 46 |
} |
| 47 |
return paddingChanged || result;
|
| 48 |
} |
| 49 |
} |