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.
Related
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 have a standard list where the rows contain images and textviews.
I would like to have the ListView's default listSelector to show up at the highest Z-index. Currently, it shows the animation under/behind the images. I want it to show the listSelector animation on top of the images and TextView.
Is this possible without creating a dummy ImageView in the row itself?
As per freddieptf's comment, the solution is to set "drawSelectorOnTop" to true on the ListView.
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:drawSelectorOnTop
I want to add dividers to listview with specific width, like the foursquare app on tips list:
I don't know the proper way to do it, i tried adding a line on bottom of each item view, but the last item have a divider too, i know its a wrong way.
Is there any way to make the divider width the same of the text content?
You can set any arbitrary Drawable as a divider by calling ListView's setDrawable() method. If you know the width of the content you intend to display you can use that knowledge to make an appropriate graphic.
Also be aware that you will need to call setDividerHeight() if the drawable does not have an intrinsic height.
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.
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.