Reputation: 5295
I am trying to achieve view hiding with respect to the scrolling of a listview.
Like in facebook app:-
1.)When listview is scrolled down, the bottom blue layout (Status, Photo, CheckIn) starts to slide up with respect to the amount of listview scrolled and finally becomes visible
2.)When the listview is scrolled up , the bottom layout slides down and finally invisivble.
3.)When the list is scrolled up and down simultaneously, the layout also slides down and up with respect to it
Now, i am trying to achieve it with translation but the result is not quite the same :-
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
final int currentFirstVisibleItem = view.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
// Scroll down
count = count + 20;
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
// Scroll up
count = count - 20;
}
bottom.setTranslationY(count);
mLastFirstVisibleItem = currentFirstVisibleItem;
}
With this code, the view slides but it is not smooth.
Upvotes: 1
Views: 707
Reputation: 20500
I'm doing something like that in my app. Except that I don't scroll the bottom but the tabhost instead. Maybe you can take out a little of code from here for you.
listView.setOnScrollListener(new AbsListView.OnScrollListener()
{
@Override
public void onScrollStateChanged(AbsListView absListView, int i)
{
if (i == SCROLL_STATE_IDLE)
{
mLastScroll = 0;
if (mTabHost.getTranslationY() >= -mTabHost.getHeight() / 2)
mTabHost.animate().translationY(0).start();
else
mTabHost.animate().translationY(-mTabHost.getHeight()).start();
}
}
@Override
public void onScroll(AbsListView absListView, int i, int i2, int i3)
{
if (absListView.getChildCount() <= 0)
return;
View c = absListView.getChildAt(0);
int scrolly = -c.getTop() + absListView.getFirstVisiblePosition() * c.getHeight();
if (mLastScroll == 0)
mLastScroll = (int)(scrolly + Math.round(mTabHost.getTranslationY() / 0.7));
float dif = 0;
if (mLastScroll - scrolly <= 0)
dif = mLastScroll - scrolly;
else
mLastScroll = scrolly;
if (dif * 0.7 < -mTabHost.getHeight())
{
dif = Math.round(-mTabHost.getHeight() / 0.7);
mLastScroll = (int) Math.round(scrolly - mTabHost.getHeight() / 0.7);
}
mTabHost.setTranslationY(Math.round(dif * 0.7));
}
});
Upvotes: 1