ListView content being added at bottom instead of top
I'm using ListView to display a list of data elements. Previously the height was set to wrap_content and it was working fine but with few performance lags. Then I came across a blog saying ListView's height should not be set to wrap_content for good performance. After doing this, i.e. setting height to fill_parent, all of my data rows started appearing at bottom of the ListView instead of top. Can any body point to what possibly I'm missing. Thanks in advance.
add this attrubut to your list view android:stackFromBottom="false"
Related
I want to display a list without scrolling vertically. if list height greater than the parent list must start from the next column. if column fit to the parent it must scroll horizontally. Image shows what I want. please help me to solve this problem
In that case you can use a constraint layout. But the logic to break the list should be implemented by you when binding the adapter with the data and view. Recycler view will be a good container. I hope this sheds some light.
I have a listview, the listviews width and height should be set to match parent. So, if the listview is fully stretched and has only 2 items in it, they are at the top of the listview and on the bottom is too much useless space. I want to know, if it is possible to center these 2 items in this listview vertically, if yes, how?
List height depends on the height of the list item, that is populating the list.
If you have only two items in the list why don't you simply use a Linear Layout instead with weightSum?
Anyway, if you want to achieve the result you requested in your question you have to get the display height using method
getResources().getDisplayMetrics().heightPixels in activity context.
After that you need to set the height of the list item to the height you retrieved earlier divided by 2.
And also set gravity to center_vertical for the textviews in the list.
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.
I thought I would have trouble adding a ListView as a header to an existing ListView because both have scroller container. But that part works fine, the header ListView gets automatically scrolled with the parent ListView.
The only issue I have is that the ListView in the header always shows just one element even though its adapter dataset contains more than one element. I tried setting its layout parameters (height to WRAP_CONTENT) programatically but I couldn't fix this.
Does anyone have an idea what is causing this behavior (only one visible element from the header list) ?
Wrap content height does't work on list view. If you want. Try to set fix height for your listview(header).
And keep in mind, nested listview maybe a bad idea.
Related issue from here i guess as per K_anas.
I've been trying to get this working for some time... Is there any way to put a transparent fixed header on a listview, so it looks kind of like this:
As you scroll up, the header will eventually be a regular header with item 1 below it.
I guess I'll have to implement onScrollListener and do something like when the first visible item is item 2 in the list, start moving the listview margins by 1 pixel, until it is below the header? Or are there better ways? Any ideas on how one would do something like that?
I would make a FrameLayout... and put your ListView in it first, filling the screen. Then put a TextView on top of that. To get the desired behavior at the top, maybe have a blank element at position 0 of the list, or just make the top padding of list item 0 have the height of your header...
Does that make sense? The ListView should scroll underneath the TextView in a FrameLayout.
You can use a RelativeLayout for that, so you can get the Z axis using some properties;)
Update:
For example using a RelativeLayout:
RelativeLayout
----ListView
----TransparentHeader
Will appear in the way you show on your image.
As a comment :Android put layout elements in the order that they are defined on your xml, so, widgets at the bottom of the layout will be at the top.