ListView - scroll an item so it touches top of view? - android

Possible? I know there's smoothScrollToPosition() (in api >= 8), but that doesn't make the requested element touch the top of the listview. It just says that the item will be visible.
I imagine I could measure each item somehow and set the scroll position manually, this doesn't help on my last few rows though, since those should not be allowed to scroll to the top anyway.
Use case - I want me users to pop open the keyboard and comment on an item in my ListView. The ime keyboard will cover some portion of the screen, so I want the 'focused' row to be touching the top of the view so they remember what they're commenting on.
Thanks

I think you can add a big & empty footerView when your user open the keyboard.
and remove the footerview when user close the keyboard.
if you add a big footerview, you can use ListView.SetSelection(last_row_pos)
After that, the last row will touch top of view.

I think you can use a set of flags in your manifest under your activity element which will allow you to do this. Please check the docs to see what your various options are.

Related

How to go past the last item in a recycle view when scrolling up

I have a recycleview that I like to go past the last element when I scroll up. The reason I need to do this is that I have a floating button that if I don't go past the last item, the floating button covers the right part of the last item. I have seen this done in apps such as WhatsApp (see screenshot).
My approach has been to add two empty items to the end of my list and then set visibility of views based on if the items are empty or not. I feel this is more a hack and I was wondering if there is a better way around this.
Below is a screen shot from WhatsApp where at the end of the list, the list scrolls further.
Thanks in advance
There is not need to add two blank items to recyclerview. It may introduce bugs as well while adding new items to the recyclerview. You just need to provide paddingBottom to the recyclerview equal to the height of floating action button and set clipToPadding = false to the recyclerview.

Leanback.DetailsFragment not scrolling as expected

I have a details fragment that is using a DetailsOverviewRow and FullWidthDetailsOverviewRowPresenter. When the page first loads the action buttons are selected. When I press down once, focus leaves the buttons and nothing else happens. When I press down a second time focus moves to a ListRow that is further down the page. I'm trying to figure out why the overview, or body as it's called in the presenter, section doesn't focus.
Should there not be a second 'state' between the two screenshots where the overview/body is readable?
Possibly of note. The DetailsFragment isn't declared in an activities xml, I'm changing fragments manually using FragmentTransactions. Also, the Fragment is instantiated using a static create method (source below).
Thanks in advance.
Activity xml
DetailsFragment java
I haven't tried this example in particular, but from my time spent with Leanback support library, I learned that even though a lot of helpful stuff is indeed provided, a lot is not :D
So I would try these things:
1) Make sure that something in the area you want visible is focusable. (Clickable elements should be focusable by default, but better check too) What I mean is that on the screenshot, there is just text, no buttons or editable content in that area. So when you press down, there is nothing to focus. What happens if you make the body TextView focusable?
(Yes, one would expect that the support library would take care of that, but that might not be the case.)
2) Find out what actually gets focused when you press down, since as you said, the focus leaves the buttons - but where does it go? (How to find out which view is focused?) You might have a "direction problem" somewhere. That is - the focus travels based on the view hierarchy tree, not based on what we see on the screen. In some cases, it is possible to skip some elements or get stuck somewhere by moving focus through an unexpected part of the view tree, that makes sense for the algorithm, but isn't logical from the human perspective.
The details presenter focus works this way :
1) First focus is given to Action buttons. Right/left nav press shifts the focus right/left between action buttons.
2) Down nav press from actions row shifts the focus from actions row to details row (individual details items itself are not focusable), this is achieved by shifting the Thumbnail anchoring position to further south.
3) Down nav press from details row shifts the focus from details row to related row.
So the details row gains focus by changing the anchoring position of Thumbnail image. Is your thumbnail image changing its anchoring position when pressing down from actions row?
Hate to answer my own question. This was due to my failure to RTFM. I was creating the fragment UI after a network request completes. For the FullWidthDetailsPresenter to work properly it and the ClassPresenterSelector() should be initialized in the fragments onCreate() method.

ListView with moving header?

I want to create listview with header which move with listviews scrolling. I tried it :
ViewGroup listviewheader = (ViewGroup) inflater.inflate(R.layout.listview_header , list1,false);
list1.addHeaderView(listviewheader);
But it only appears when user rise to top of the listview. I want that when user rise a little bit (everywhere in listview) then the header appear in top. How can i do it?
Check this library: https://github.com/ManuelPeinado/QuickReturnHeader
"A ListView/ScrollView header that hides when scrolling down and reappears immediately when scrolling up, regardless of how far down the list we've gone. Like the one from the Google Keep app."
https://github.com/felipecsl/QuickReturn
-- Quite easy and useful implementation

Adding a new item in a horizontal ListView when over scrolled to the right: Android

I have a Horizontal ScrollView that shows a number of items. I want to show an extra item only when the user over-scrolls to the right.
Then when the user scrolls back to the left this extra item should disappear. The View should normally scroll only in the first item and only on explicitly doing an over-scroll the extra item should be visible.
I am not able to figure out how to do this. Could someone please provide pointers on how to achieve this behaviour.
Thanks
Sunny.
The easiest way I would do it is define that extra item in the scrollview, but set it's visibility. You can do it in code. Here's a snippet.
yourobject.setVisibility(View.GONE);
yourobject.setVisibility(View.VISIBLE);

Listview disable scrolling optimization

In listview when it is scrolled, the top item which is going out of scene is attached at bottom which is coming in to scene.
Is this behaviour fixed or we can disable this feature.
In my listview, i got only 10 items so this feature is not that important to have.
If you ignore the "convertView" parameter on your Adapter.getView(), the old view will not be used, but it will be regenerated when you scroll back.
If you don't want this behavior, use a LinearLayout.

Categories

Resources