Android ListView scroll to the middle of the view - android

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.

Related

Allow Recyclerview Items to scroll past top of Recyclerview

I have a RecyclerView list, in which I want the currently selected item to be shown at the top of the RecyclerView. I still however, want the entire list to be scrollable, therefore, removing views from above the selected item is not a possible solution.
It seems I need a mechanism where the RecyclerView items are able to scroll beyond the bounds of the RecyclerView. I'm not sure if this is possible, so if it is not, does anyone have a solution to ensuring the currently selected item scrolls to the top of the RecyclerView.
I have tried smoothScrollToPosition() but this doesn't work in the case of being at the bottom of the RecyclerView, and wanting one of the middle items to scroll to the top.
Many thanks
to Illustrate, I have a list of 4 items, the recyclerview cannot scroll as there is not enough items in the list.
Then I select an item
I then want the selected item to scroll to top, but for the item above to still be scrollable.
So, when I scroll up...
On the RecyclerView set a bottom padding that is equal to three times your item's height then set android:clipToPadding="false". This will let your bottom item scroll to the top and show the padding on the bottom item but only on the bottom item.
Here is an answer to a similar question that lays this technique out rather well.
lets assume that you have item on click listener for your recycler view, when user clicks on any item you get item position and view, below code is working for me
RecycleClick.addTo(firstRecyclerView).setOnItemClickListener(new RecycleClick.OnItemClickListener() {
#Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// YOUR CODE
int offset = position - yourRecyclerViewLayoutManager.findFirstVisibleItemPosition();
if (yourRecyclerViewLayoutManager.findFirstVisibleItemPosition() > 0) offset -= 1;
yourRecyclerViewLayoutManager.scrollToPositionWithOffset(position, offset);
}
});
make sure your layout manager comes from support library like this
android.support.v7.widget.LinearLayoutManager
otherwise you will not find findFirstVisibleItemPosition() method etc

Android facebook bottom bar animation

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.

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.

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/

Making child ListView scroll

Hello I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:
http://nan-technicalblog.blogspot.com/2008/12/android-how-to-use-horizontal-scrolling.html
It works great as far as horizontal text goes it does exactly what I want but I am unable to get the ListView inside the custom LinearLayout to actually scroll veritcally. I have tried passing the Y coordinates from the onScroll method to mListView such as:
mListView.scrollBy(0, distanceY);
but that seems to move the custom LinearLayout window instead of just scrolling the ListView. I can tell that the ListView is not scrolling because the window moves without the vertical scroll bar of the ListView moving. Everything just slides around. Any help would be much appreciated.
Okay this one also took me about a week in my spare time to figure out. I had to change the supplied code for dispatchTouchEvent to this:
public boolean dispatchTouchEvent(MotionEvent ev){
mGestureDetector.onTouchEvent(ev);
mListView.onTouchEvent(ev);
return true;
}
Also changed onScroll to return false just for good measure.

Categories

Resources