ListView Only add enough items to fill screen - android

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.

Related

Recyclerview with item displayed horizontally and various width

On my Android app, I am trying to create a list of tags on top of a recyclerview. the goal is to have a kind of filtering feature. The screen will be composed of 2 recyclerviews.
The first one contains buttons with name inside which will be used later as a filter. You can click on one or more buttons and update the list of videos displayed in the second recyclerview.
The second recyclerview is just a list of items (in my case video) displayed vertically.
The system works fine, but I am having trouble to have the look I expect for the part where the buttons have to be displayed. I tried to have them order horizontally, and it's show them vertically. I tried using Grid, but Grid is creating a grid with fixed column width when in my case the column width has to adjusted to the button size. The width of the button is just depending on the length of the text.
I am using the code below, but it's not doing with I need:
binding.tagLayout.apply {
layoutManager = LinearLayoutManager(activity)
tagAdapter = TagAdapter(context, tagList).apply {
adapter = this
}
}
This is just getting me a vertical list. When I try to get something, as below:
The image above is not the design, but it gives an idea of what I expect. I just want to create a list, where the item are displayed horizontally and when reaching the end of the screen, we go to the next line. I could have 2, 3,... buttons on one line, the number of items displayed in one line, is based on the size of each item.
Any idea ?

How to scroll down to the footer of a list view and show the whole footer

I have a long list with a big header and footer and I need to scroll the list all the way down and show the whole footer.
Also, items can have very different height so the overall height cannot be simply calculated height * no items.
All the existing questions I've seen do not take in account the footer might be big and not entirely shown when scrolling to last position.
So far I've tried:
1) the simplest solution:
lv.setSelection(lv.getCount() - 1);
However this will not show the whole footer, only part of it and I need to have it all visible.
2) using:
requestFocus();
on the footer, the main layout in it, and any elements in the footer: this changes the focus but doesn't force the listview to scroll down.
3) using:
lv.scrollTo(x, y);
problem with this is that I couldn't get the real height of the listview in a reliable way as items are not fixed size.
Beside, after scrolling often part of the list is not shown leaving a wide white area.
4) header and footer are contained in two adapters but I couldn't figure out how to reach them to be shown on the screen
5) I have also tried a mixed approach:
lv.setSelection(lv.getCount() - 1);
lv.scrollListBy(mFooter.getHeight());
But the scrollListBy() doesn't seem to have any effects after a setSelection - not sure why.
Does anyone have any suggestions?
Thanks in advance

Show Row Per Row While Scrolling Listview -- Android

I have a listview with rows as big as the device screen and I want to show row per row while sliding, I don't want to show parts of rows when doing so, is there any way of doing it.
ListViews are not made for this kind of use case. ViewPagers are, but they scroll horizontally. It's possible to make it scroll vertically (see Android: Vertical ViewPager), which should be what you're looking for.
The problem with adjusting the size of each ListView item to fill the screen is that match_parent simply doesn't work. You would need to calculate the exact size you need (screen height minus action bar and other views that are not part of the ListView). It's probably possible, but not worth the trouble.

Android listview with custom layout header and footer

Sory I can't describe a right title for my question,
I want to create listview something like this
In top of list view on screen look like
and when user scroll the list in screen will be like this
and in end of list is
I have 3 picture for top list, middle and bottom list.
I already try to add header and footer for top image and bottom image but looks like the picture is inside the list view
I try to create vertical linear layout and put picture top,middle and bottom in sequence but still not get result that i expected
Do anyone have a suggestion for listview like this
Don't set your frame background for entire listview or its parent. Instead first slice your frame background into three parts, (i) topframe (ii) middleframe (iii) bottomframe. Now create a custom listview and set background for each and every list rows.
In order to achieve your design, you need to find the first and last item of list and set topframe for first row and bottomframe for last row , all the other rows background should be middleframe.

How to create a gridview with spacing at the top

I was looking to create a GridView that stretches across the entire screen. However, when the user first opens the screen, the top of the first item should be about halfway up the screen.
For example lets say we have a GridView of 12 items displayed 3 x 4. When the user first opens the screen, only the first six items would be seen with a large margin at the top of the screen. The user can then scroll the list to see the other items. The top items would eventually reach all the way to the top of the screen.
If I was using a ListView, this is simple. I merely create a 0dp headerView with a large top margin. But, GridViews do not allow for headers. What is the best way to handle this situation?
Normally, you DO NOT make a GridView inside a ScrollView. It's not recommended! But sometimes you have no choice and you need to addHeaderView() on a GridView (But I repeat, it isnt recommended).
So, to make this happen, you have to make a custom GridView. This answer will be usefull in your case: Grid of images inside ScrollView
I had a same situation and I used this one: HFGridView by #SergeyBurish! Very simple and really great. (See the last answer here: A GridView with header and footer).
Hope this will be helpful.

Categories

Resources