Android facebook bottom bar animation - android

I want to implement a slide up/slide down animation on bottom bar when scrolling the screen up/down.
Implementation has to be like in facebook app when the user slide up/down the bottom options bar slowly slides up/down .
I tried using scrollview to get the scrollchanged method to identify the scrolling behaviour of user and hide the bar based on the events.the tricky part is how to animate it slowly based on user slide up/down.
tried using moveup/move down animation but it was not fluid as the next animation starts when the first one ends . so the movement of bottom bar is more animated.

The proper name to that behavior is "quick return pattern" and you can implement it with this gist:
https://gist.github.com/JohNan/df776dc4926a1676cc05

Referring from the post of #baniares
https://gist.github.com/JohNan/df776dc4926a1676cc05
Used the on scroll method to compute the scroll of slideup/down and settranslate method to update my view.
public void onScrollChanged(ObservableScrollView scrollView, int newX,
int newY, int oldX, int oldY) {
if (scrollup)
{
<View>.setTranslationY(0);
}
else
{
<View>.setTranslationY(position+1);
}
}
The value 0 should be used in .settranslateY to bring to original postion of view. Increasing the value will translate the view to make it slide down.

Related

Android CollapsingToolbarLayout custom snap scrollflag

I am trying to control the scrolling behaviour of snap scroll flag of collpasingtoolbarlayout . According to this tutorial link
SCROLL_FLAG_SNAP: Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to it's closest edge. what I'm trying to achieve is to make the Snap Behaviour works in 1 Direction only from Bottom to Top . which means if that view is close from the top edge and the user is scrolling from the bottom it should work normally in this cause. otherwise, for ex if user scrolling from top to bottom it should do nothing.
Here is a gif of Santa application of Google which I'm trying to achieve the same behaviour .
Gif Link
Here's a link to a post that was made before the support for the snap scroll flag which includes code that recreates the same behavior. You might be able to modify this custom behavior to fit your needs.
In that code you will find the following section which you need to edit for your "close to top or bottom" logic:
if (topOffset < -(scrollRange / 2f)) { //Close to top
// Snap up (to fully invisible)
animateOffsetTo(-scrollRange);
} else { //Close to bottom
// Snap down (to fully visible)
animateOffsetTo(0);
}
You will also need to include logic to compare the offset at the start of the scroll to the offset at the stop of teh scroll to determine the swipe direction.
Good luck!

Android ListView scroll to the middle of the view

I have this problem with Android ListView. My View consists of ListView and two floating buttons on the bottom of it. These two floating buttons overlays the last item of the ListView. On the iOS side by default you can drag last ListView's item to the middle of the View and in this way it's possible to see what item it is. When you release the last item it scrolls back to the bottom of the page. On the Android part by default the last item of ListView doesn't drag to the top so that it would create some space after it. Any ideas how it's possible to achieve this kind of behaviour?
This isn't really the default behaviour you would want on android, however I think it's possible to achieve it using the following method: https://stackoverflow.com/a/12424780/2350917
I have never tried it though, so tell us how you got on.
Edit:
#Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
if(scrollY < 0) {
smoothScrollToPosition(0);
} else if(scrollY > MAX_SCROLL) {
smoothScrollToPosition(getAdapter().getCount());
}
}
Edit 2:
The best method to solve this and to follow android guidelines, would be to show the floating action buttons when you get to the listview screen and then make them disappear as you scroll down. When you scroll up they would appear again. Like this you could see the content on the last item of the listview.
This method would work if it is not essential to show your floating action buttons ALL the time.

Vertical MenuDrawer and ListView scrolling up issue

I have a problem which I am not sure how can I handle.
I started using a library called MenuDrawer on which I have given the following:
mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
Which allows it to pop open whenever I drag the screen down, but this actually rises another issue for me, because I use a ListView there that needs to be scrolled also.
I actually have 2 questions, taking in regards that not all may have used this library.
If you have used this library: Is it possible to focus the dragging on just 1 element? For example if I have a TextView there can I drag only that item to open the menu?
If you haven't used this library: How can a child element steal the focus from the parent on touch event? So that when I touch and drag somewhere where the listview is to achieve a successful scrolling up and down.
Right now I can scroll freely only down and when I try to scroll up opens the menu, unless I scroll the listview first down and up without breaking contact with the screen.
I found how to manage that. For me this simple piece of code worked like a charm:
mDrawer.setOnInterceptMoveEventListener(new OnInterceptMoveEventListener(){
#Override
public boolean isViewDraggable(View v, int dx, int x, int y) {
//v.getId();
if(y > 50){
return true;
}
return false;
}});
if anything below Y 50 is pulled it won't trigger the menu drawer.

Add Fixed button inside scrollview which is visible even when scrolling

I want to make a view( a button actually) which is inside a scrollview , but when the user scolls down and the button is going up, it moves up only till it reaches the top of the visible screen and then stays there like a fixed header until the user scrolls up again and then it returns to its original position.
I have given the screens for a better understanding.
One way I have solved this is by copying the same view outside the scrollview and keeping it hidden. Only to make it visible when the old button is visisble again.
#Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy) {
Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (mPriceBtn.getLocalVisibleRect(scrollBounds)) {
// View is within the visible window
mPriceHiddenBtn.setVisibility(View.GONE);
} else {
// View is not within the visible window
//mPriceBtn.setY(y);
mPriceHiddenBtn.setVisibility(View.VISIBLE);
}
}
Check out this tutorial. It's about an ActionBar with similar behavior, made by ome of Google's own Android devs. I'm guessing you can find most of what you need there.

Get the position of scrollbars(not the position item) in a ListView

I am implementing a timeline UI, which is basically a ListView. The tricky part is when the user scrolls the ListView, it will display a text box(shows the time slot, say 9:00 am ) next to the scrollbar. It is on the left side, adjacent and will move with the scrollbar.
I am using the OnScrollListener to detect the scroll event. But I don't know how to get the exact position of the scroll bar (top, mid point, bottom), so that I can put the text box at the right place. There are many posts about getting the position of the top item but seems not for the scrollbar itself.
Any thoughts?
BTW, sorry for not attaching a screenshot of the UI. Stackoverflow doesn't allow me to do that since I am a new user.
But I don't know how to get the exact position of the scroll bar (top,
mid point, bottom), so that I can put the text box at the right place
You probably want something like the Path application. This tutorial it what you're looking for(probably, if you didn't see it yet).
Basically, the ListView has some methods regarding the scrollbars position(also size) that are used but those methods are not available from outside as they are declared as protected, so you need to extend the ListView class. Those methods are ListView.computeVerticalScrollExtent(), ListView.computeVerticalScrollOffset() and ListView.computeVerticalScrollRange().
Using those methods you should be able to figure where the scrollbars are placed at a particular moment in your listener.
getListView().getLastVisiblePosition()
listview.post(new Runnable() {
public void run() {
listview.getLastVisiblePosition();
}
});
View.getScrollY()
getScrollY:
Return the scrolled top position of this view. This is the top edge of the displayed part of your view. You do not need to draw any pixels above it, since those are outside of the frame of your view on screen.
Returns
The top edge of the displayed part of your view, in pixels.
Also refer : http://eliasbland.wordpress.com/2011/07/28/how-to-save-the-position-of-a-scrollview-when-the-orientation-changes-in-android/

Categories

Resources