I have an expandable list view I am using in one xml file which has a background. Upon loading, it looks fine, but sometimes while browsing the background of each list element shows infront of the background of the base view.
The list elements are defined in their own xml file.
Can I make the list elements backgrounds become transparent somehow, so that the background of the baseview is shown all the time instead, even when expanding/collapsing the view?
The answer can be found here :)
http://developer.android.com/resources/articles/listview-backgrounds.html
Use
android:cacheColorHint="#00000000"
On your list
Set this all four properties for expandablelistview. It worked for me....
android:childDivider="#android:color/transparent"
android:listSelector="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:background="#android:color/transparent"
Or programmatically set expandablelistview transperent:
ExpListview SecondLevelexplv = new ExpListview(mContext);
SecondLevelexplv.setBackgroundColor(Color.TRANSPARENT);
SecondLevelexplv.setCacheColorHint(Color.TRANSPARENT);
SecondLevelexplv.setDivider(new ColorDrawable(Color.TRANSPARENT));
SecondLevelexplv.setSelector(android.R.color.transparent);
Related
I have an Activity with a ListView, I set the background image to the view programatically.
When I scroll down my list, the background image turns to white ( because my theme is Theme.Light.NoTitleBar).
How can I make it scroll with the blue background intact?
If the above point works, how can I change the text color of ListView to white instead of black?
Normal ListView
Scrolling ListView
Pressing ListView item
Use the attribute android:cacheColorHint="#000000" in ListView Tag
Regarding make TextView's color black or white, you can refer here to make a custom TextView for your ListView row, The extra work you have to do is just add another attribut inside TextView tag like this
android:textColor="#FFF" //or #FFFFFF for white
add a attribute on the ListView Tag
android:cacheColorHint="#00000000"// setting as a transparent color
This is due because of an optimization. To remove this, just set the cacheColorHint of your listView to transparent, like this: android:cacheColorHint="#00000000"
Full post here: http://android-developers.blogspot.fr/2009/01/why-is-my-list-black-android.html
You can Wrap that ListView inside on LinearLayout having same background and then remove ListView's Background that should work fine. :)
Please check this answer. I have got the same issue and it is fixed by putting view = null in adapter side.
I've created an android application with a ListView. I've added both a header and footer to the list. But when adding a divider/separator it also creates an empty space between the header and the first ListView item. It does the same for the last ListView item and the footer.
The empty space is equivalent to the size of the divider between all the ListView items, with the difference that it doesn't draw the divider and just leaves empty space. I thought I found the solution with the xml attributes 'Footer dividers enabled' and 'Header dividers enabled'. But when setting them to false, it doesn't change anything. I even tried to set them programmatically with
list.setFooterDividerEnabled(false);
list.setHeaderDividerEnabled(false);
But it just doesn't work. Any way to fix that problem? I just don't want the empty space to be there, I want the first item to fit exactly to the header (same for the footer).
I stumbled upon the same problem, but in a slightly different situation than yours. My ListView has a header (a search box), but the first item below it contains a section header (a date, or a letter) rather than being a regular list item (with the actual content in form of an image, some text, and so on). As such, I want it not to be selectable, so in my custom adapter I have overridden areAllItemsEnabled to return false.
Big mistake, because that's exactly the culprit. See, it appears that, by design, the ListView implementation only draw dividers between two enabled items, but still reserve space for dividers between an enabled item and a disabled one even if those dividers will not be drawn. The fact this is a conscious design decision does not mean it's not stupid, of course. Most weird of all, this dividers drawing policy is based just on the value returned by areAllItemsEnabled instead of the values returned by single calls to isEnabled for subsequent items.
Thus, to work around it, I just had to return true from areAllItemsEnabled (I kept the overridden method and add a comment about this issue, otherwise I would not be able to remember it a month from now): lo and behold, white space disappeared, replaced by a divider. Now, if I want to show the ListView header and the first section header as being exactly adjacent, I just have to choose a divider color that's the same as the section header color.
Really hope that's the same case as yours, or that my solution helps you in some other way.
I tried a solution by 幻影浪子 that works (based on android-pulltorefresh):
View Layout (header.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ProgressBar
style="#android:style/Widget.ProgressBar.Small.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:layout_marginTop="2dp" />
</RelativeLayout>
</LinearLayout>
Inflating View:
m_headerView = inflater.inflate(R.layout.header, this, false);
Displaying View:
m_headerView.setPadding(0, 0, 0, 0);
m_headerView.setVisibility(View.VISIBLE);
Hiding View:
m_headerView.setPadding(0, -1000, 0, 0);
m_headerView.setVisibility(View.GONE);
It worked perfectly in our project. I hope it is helpful.
In getview method you can check if the item is first or last and set custom devider which will be of 0 height or single pixel height of transparent color.
goto the ListView properties in android layout and search for spacing tag... some how in android, when creating new layouts, it will defaults creation is spacing header spacing and border properties. check it , if it is available then remove it
Didn't find a great solution.
Set dividerHeight="0dp" and created my own dividers manually - either directly in the layout XML or dynamically in the adapter if you need more precise control.
Just do
list.setDividerHeight(0)
That should take care of it.
i have a listview with a bunch of items in it, each item has its own background, the problem is that if i only have one item in a list, the rest of the "empty" slots of the list is black. I tried applying a background around the listview and also on the view that sorrounds it (relativeView) and i get a strange margin around the whole list like the picture at the bottom. The question i have is, how can i remove the actual "borders" around the list so it still fills upp its parent ? .
Remove any padding you may have used in your XML layout file.
Try putting in the following code in the listview's layout:
android:cacheColorHint="#00000000"
Change your listview height like this android:layout_height="fill_parent"
use android:fadingEdge="none" in listview in layout
This question already has answers here:
Background ListView becomes black when scrolling
(12 answers)
Closed 9 years ago.
I have a custom list view and I want the background of the list to be white, so I do something like this which works great.
listView = (ListView) this.findViewById(R.id.listview);
listView.setBackgroundColor(Color.WHITE);
The problem is when you scroll the list the background of all the list items changes to black, which looks horrible.
I tried in my list view setting the background color to white. When I inflate the view I also tried setting the background color to white:
view.setBackgroundColor(Color.WHITE);
Both of these fix the problem of the scrolling background color, but now the item doesn't appear to be clickable even though it is. What I mean by that is the onClick still works fine, but the background doesn't flash to orange to let the user know he clicked it.
How can I have a white background in a list view, that stays white while scrolling, and does the normal list acitvity orange click background?
Thanks!
The solution is very simple, you also need to set the cache color hint to white: setCacheColorHint(Color.WHITE). You don't need to change the list items' background color.
ListView lv = getListView();
setCacheColorHint(0);
Set the cache color hint to zero.
Solution is very simple, you also need to set the cache color hint to black in xml.
android:cacheColorHint="#000000"
Android attempts to improve the performance of ListView scrolling by caching layout information. If you have long scrolling lists of data you should also set the the android:cacheColorHint property on the ListView declaration in the Activity’s AXML definition (to the same color value as your custom row layout’s background). Failure to include this hint could result in a ‘flicker’ as the user scrolls through a list with custom row background colors.
So give the same color to the listitem's background and android:cacheColorHint.you can refer below code.
In my Adapter layout I gave as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ADAPTER_CONTAINER_PRIMARY"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FAFAEE"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
.....
And in the List view
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LIST_GRID_LIST_INSTANCES"
android:focusableInTouchMode="true"
android:smoothScrollbar="true"
android:divider="#drawable/Gray"
android:dividerHeight="0.05dp"
android:cacheColorHint="#FAFAEE"
android:background="#drawable/round"/>
If your ListView is drawn atop a more complex background -- say, a bitmap or gradient -- then you may need to disable the scroll cache entirely. I ended up setting android:scrollingCache="false" on my ListView to resolve this issue.
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:scrollingCache
I have one expandable list view and i need to set background to Expandable list view.
How to set this background?
You need to set both the background color AND the cacheColorHint to the same color (black, in the example below). If you don't, the list will appear to flicker as you scroll through it, same as a regular ListView.
<ExpandableListView
android:background="#000000"
android:cacheColorHint="#000000"
... />
Also, your child views will be drawn over the ExpandableListView, so make sure you aren't setting their background colors unnecessarily.