ListView last item aligned to the bottom - android

I would like to have last item of the listView aligned on the bottom.
In case there are 1 to several items on the list, there should be an empty space between last item and second to last item.
In case there are many items (they do not fit in the list, scroll is shown), the list should behave normally.
I tried to make it so that when list consists of some small hardcoded number (6) of items (or less), last item is separate view aligned to the bottom of the parent of the listView. When there are more items, I set visibility of this view to GONE and added same view to the listView. It was working fine, but not for all devices. Some fit 6 items, but others fit 7.
Is there any way to align last item to the bottom of the listView (so the listView has always the same height as its parent)?

Maybe the easiest way to implement this will be just to add your last element as footer using addFooterView

Related

ListView Only add enough items to fill screen

I have a listView that is populate via a RSS feed. The height of each item on the ListView can vary depending on the length on the content. Is there a way to only add enough items to the listView to fill the screen (the listView has a fixed height).
For example if each item only has one line of text I can fit 7, but if they have two lines of text I can only fit 5. I want to be able to programmatically decide when to stop adding items. I don't want the ListView to have to scroll.
EDIT
Let me rephrase. I don't want to just solve it but scrolling down. There may at some point in the development be content that gets added below the screen and requires scrolling but even in that case I don't want half an item showing at the bottom. Basically I don't want broken/half items showing at the bottom, if it's on the screen it should be the whole item that is showing. If not it should be below the bottom of screen.
Try using a normal Linear Layout and when adding the inflated row, override the onMeasure to know if it fits on the screen.

Vertical ViewPagers(kind of) thing using a list(recyclerview or listview)

What I want to achieve is that when the list is populated in recyclerview, every list item when scrolled up or down should be displayed as one item in the list only(covering whole of the space provided for the recyclerview). In other word, lets say that each list item should match the height and width of recyclerview. When the list is scrolled all the big listitems can be seen scolling but when scrolling ends only one view is displayed.
If still not clear, I just want a recyclerview to show only one item at a time and if we want to see other list items we have to scroll.
Similar to what a view pager but vertical in direction and should be using a recyclerview.

How to achive ListView with Search functionality and Search box should also scrollable?

As Shown in image 1: I have listview with 2 items(half empty),and at the top i have one serch box I complete search functionality with custom adapter and Filterable but i want some other thing with this .they are
want to scroll listview with half empty(By Default it scrollable when Items more than area)
Search box should also scroll with listview.(As shown in 2 picture.)
listview should be scroll up to last item (Here last item is Item2 should always shown )and item at top should highlighted with different color.
Scrollview can have only one direct child. So if you want to put more than one view in a single scrollview, you should put all the views you need to scroll, inside single container view eg:-linear layout and put those views in that.

scrolling in listview with different cell height

I have a listview and its rows have different heights.
When I scroll up, rows appear to move up or down erratically.
(I don't find the behavior when I scroll down)
I suspect its due to the fact
listView picks one of used rows
the row is placed on top of visible rows.
listView changes the row's height(here erratic movement)
but it's a guess.
I tried googling since this should be a common problem but couldn't find any.
In this case, setting the right item height did the trick :
How to set different heights for each row in a ListView?
Edit: oh, and make sure you recycle the items correctly :
ListView reusing views when ... I don't want it to

Does ListView expect the selected row from setSelection() to be on the top when a user scrolls?

I have a ListView which has overlayed on top of it another view which I call a Header. This header can be of various heights.
On ListView's dataset, I insert in a blank row, and programmatically set the height of this row to be the height of my Header view. This way when the ListView loads, the row at position 1 (the actual first row of data) is lined up to the bottom of the header. I do this so I can set the Header view as partially transparent and when the user scrolls they see the rows of data mix with the transparency of the Header view.
Now I have one use case where I can navigate to this list and a given row will be selected. What I've done is call setSelection with position X. This will automatically scroll my ListView so that the top of row X is at the top of the list. However, my Header view still obscures this. To compensate I call scrollTo. These two pieces are something as such:
listView.setSelection(selectedRowPosition);
if(hasHeadersEnabled()) {
listView.scrollTo(-headerView.getMeasuredHeight).
}
When I call these lines of code, my ListView looks as I would expect. The selected row's top is to the bottom of my HeaderView. The problem I run into is that as soon as a user touches the ListView, the scroll position jumps so that the selected row's top is at the true top of the ListView (aka the Header view's top).
My question is, after you setSelectedRow on a ListView, does the ListView always expect that row's top to be the ListView's top when it starts consuming the onTouch events for scrolling? Is there another way to accomplish what I'm hoping to do with this code? I've tried scrollTo and scrollBy and both have the same effect.
So I should have looked at the API harder. Found the answer to my question.
I need to use setSelectionFromTop instead of the combination of setSelection and scrollTo. Here is the sample code:
listView.setSelectionFromTop(rowPosition, headerView.getMeasuredHeight());

Categories

Resources