I have a listview in which there should be different divider height
between different rows. So, how can we set the divider height
dynamically?
Suppose, I have 10 rows and there should be a divider height of 5
between first 2 rows and then there should be a divider height of 1
between next 5 rows and so on.
Can someone let me know the way of doing this?
One way would be to make the dividers rows. Set them as not enabled in your isEnabled adapter method. I do that for section headers, but it is almost the same thing. Another way would be to manually lay out your whole list by implementing onLayout. If the dividers can be empty space, it might work to set top or bottom margins for the root view of your rows. In xml that would be:
android:layout_marginTop='5px'
Otherwise, just make the dividers part of the rows.
Related
I'm trying to achieve a design for recycler view in grid layout style. Any Input towards achieving it is very helpful.
I have to design for span size 2 only.
Design :
I tried to use GridLayoutManager with span size 2
If you mean that list should scroll horizontally and each next column should be following of previous one. I think you can done it by horizontal recycler view with items that contain two views and top space margin which increases sequentially.
Height of the RecyclerView should be calculated and set by last column in code.
The idea is to add items to the center of the listview, and the divider between the items is of equal size and decreases if the number of items increses.
A rough sketch demonstrates what my question is about, how may i achieve this?
Are you sure you need a ListView?
Maybe you can just add the items to a vertical LinearLayout and add <Space> views (with layout_weight between them.
I was wondering if there is a way to specify how many items should fill the listview space before you need to scroll to see the others. What I mean is something like a weight to set to specify how many inflated layout should fill the listview space. Something like if I inflate 10 layouts into a listview I'd like to fill all the listview space with just 3 and then access the others 7 by scrolling so that I get all 10 items a bit bigger. Is there a way to do that? I hope I was clear enough.
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 three items in a ListView. The reason I have chosen the ListView is so I can use a Divider and a List Selector on these items.
However I do not need/want the scrolling aspect of the ListView. Ie. When I select/drag an item from the list, I dont want it to scroll..
Is it possible to disable this somehow? Or will I have to add the items using a LinearLayout and find another way of using a list divider and selector?
I'm not sure how well this will work for you, but you can disable overscroll (available in android-9 and above):
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
and then also hide the scroll bars:
listView.setVerticalScrollBarEnabled(false);
After this, if your list does not exceed the screen size then it shouldn't be able to scroll.
If you dont need to scroll listview, you can add the list item to a linear layout as well you can design it also through xml file.
And for put a DIVIDER to it just take a "View" widget.
Put it height 1 dip and width fill_parent. You can give color to this view through background color.
Try it. i have done it many times.