I found this Hide footer view in ListView?. As Yoni poited out correctly, you can hide a header in a ListView by wrapping it into a FrameLayout and setVisibility() of the inner View to View.GONE. This works almost perfect for me, BUT:
As the FrameLayout still exists, the ListView adds two dividers to the displayed list. It seems like a single divider with a height of two dividers. Is there a way to hide a single divider of a ListView? Maybe it's possible to change the divider's color to the background, that would be fine for me, too. Any complete other ideas? Perfect!
Please help me. I'm not keen on spending two more hours of trial and error.
Thanks a lot!
Together with hiding or showing your header or footer, use these functions:
setFooterDividersEnabled()
setHeaderDividersEnabled()
you can use xml attributes to hide divider for header and footer in ListView
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
you can change the dividers color like this:
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="2px"/>
For disable divider:
ListView.setDivider(null);
Related
I have the Following View in my XML. I am setting the childDivider to a color. But my child divider is not visible.
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contacts_first_level_list_view"
android:childDivider="#color/text_color_grey_directives"
android:dividerHeight="#dimen/d1"/>
Please let me know if i have to do any thing other than this to see the divider only between Childs(No Divider between parents). Thanks.
I just ran in to this problem and finally found the answer. Check to see that isChildSelectable() is set to return true. (I know this is old but it may help someone.)
I'm fairly new to Android and when I have a ListView containing only a single item that item appears at the bottom of the ListView. I'm assuming this is because the ListView is populated from the bottom. So, is there a way to get the ListView to populate from the top? Or are there any other methods to get the same result? Thank you.
Here is my definition of the ListView
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fileList"
android:layout_centerHorizontal="true"
android:layout_above="#+id/previous"/>
When I remove android:layout_above="#+id/previous the problem is fixed, but my list extends behind the button I have at the bottom off the screen.
Check the android:gravity attribute in your defined ListView in static XML. It sounds like you may have it set to android:gravity="bottom"
I was able to solve this problem by setting android:layout_height and android:layout_width to fill_parent
remove this line, list will show from top.
android:layout_above="#+id/previous"
I have a listView that expands upwards instead of downwards.
I have another listView on another page that works just fine and populates itself from the top -> bot.
Why does my listView start from the bottom instead of the top?
My XML
`
<ListView
android:id="#+id/list_view_showRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/showRegister"
android:layout_alignParentLeft="true"
android:layout_marginTop="50dp"
android:clickable="false" >
</ListView>`
Your ListView is still actually populating from the top downwards. Just not from the top of the page.
You have set the layout_height="wrap_content" and the layout_above="#+id/showRegister". With the height being wrap_content, the view will only be as large as it's contents. Then, due to the fact you have used layout_above, it will be directly above another view.
The listview is not filling from the bottom, it is filling from the top (of the listview) - but the listview itself is only starting from halfway up the screen. Anything above the listview is not actually part of the listview, but empty space instead.
The solution is to either set the layout_height="match_parent", or remove the layout_above tag.
I know this is an old question but I hope this helps anyone else who may have found this issue via google.
Have a look a these links. Is it possible to make a ListView populate from the bottom?. populating from bottom.
Add new items to top of list view on Android?. Add new item at the top of list.
See for android:stackFromBottom attribute.
I have a layout requirement like below,
Textview
TextView
ListView
Edit Text
Button
Since listview cannot fit in landscape, I want to have list view onwards (ie. listview, edittext and button) to be a scroll view.
I know listview cannot be used inside a scrollview, but is there a way to do that ?
Any working example will be appreciated.
99% of android developers think we should not use ListView inside a ScrollView because both are scrollbale views and only parent can be scrollable, so it wraps the ListView.
Its 100% correct. But we have to use tricks to avoid this and to achieve our requirements.
I found one trick in web, which is setting the height of ListView based on the list items. Just check the link below, you will get an example code to calculate the height of ListView to fit inside a ScollView.
Android ListView height calculation to fit in ScrollView
The problem with this code is the list view will be filled entire screen if more children are available.
You have to use below template to achieve solution to your requirement.
<ScrollView >
<LinearLayout vertical>
<TextView />
<TextView />
<ListView />
<EditText />
<Button />
</LinearLayout>
</ScrollView>
I saw one video on youtube, Android ListView inside a ScrollView which is showing we can limit the height of listview, can be scrollable and used inside a ScrollView. I don't know how the programmer achieved that.
I am also thinking to produce same result by avoiding above example code. I hope it may help you temporarily. Please let me know if you got solution.
The better solution for this kind of layout is that You should use relative layout and fix ur EditText and Button at the bottom of ur screen like i have in my list view(see the image below) so that you wont need to add ScrollView in ur layout.
Just do this
<ScrollView>
<LinearLayout>
<ListView>
</LinearLayout>
</ScrollView>
Then add your
EditText
Button
Sort of a round about way to do what you want to do without a scroll view.
Write a custom adapter for your ListView
Assume you have an array of n elements that you want to populate the ListView with and then the EditText and the Button. So number of elements will be n+2
In the getView for the position n+1 return a view which has an EditText box instead of the normal list item
For the n+2 position return a Button.
Don't try to wrap around a ListView with a ScrollView, you will need up with lot of issues.
Note: I have not tested this, not even sure if it will work. Do let me know if it works. :)
How can i get rid of the shadow when I scroll ListView.
I have shadows appearing on top and bottom of the list.
<ListView
android:fadingEdge="none"
...
/>
Be sure to watch your padding on the ListView. I had a Linear Layout that was in shade at the top and bottom, this was because I had set padding on the layout above and below, so it is crucial that you look at the padding.
As per this answer, android:fadingEdge="none" is deprecated since API Level 14, so rather use android:fadingEdgeLength="0dp"
android:overScrollMode = "never" works for me.
android:fadingEdge="none" didn't work.
See Remove shadow from top and bottom of ListView or RecyclerView.