Making "slide From Bottom" Button (similar To Snackbar) (Android)
there's something I want to do but don't know how... that would be a button that slides from the bottom of the screen to a certain position, triggered by something. Very similar to
Solution 1:
Sounds like a fairly straightforward animation along the y
axis, with a start value that matches the height of the screen (such that it renders just off screen), to whatever the final value is. Below code is from memory, but it should work.
To grab the screen height:
int getScreenHeight() {
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
return displaymetrics.heightPixels;
}
And to animate a view (in this case, to 80% of the total screen height):
void animateOnScreen(View view) {
final int screenHeight = getScreenHeight();
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "y", screenHeight, (screenHeight * 0.8F));
animator.setInterpolator(new DecelerateInterpolator());
animator.start();
}
Solution 2:
Sliding a View down by a distance:
view.animate().translationY(distance);
You can later slide the View back to its original position like this:
view.animate().translationY(0);
Post a Comment for "Making "slide From Bottom" Button (similar To Snackbar) (Android)"