Remove the bottom divider of an android ListView - android

I have a fixed height ListView. It has divider between list items, but it also displays dividers after the last list item.
Is there a way to not display a divider after the last item in ListView?

Just add
android:footerDividersEnabled="false"
to your ListView description

As #ScootrNova said, this seems to be behaving differently (a.k.a buggy) in android 4.4.x (I don't know exactly when the problem is introduced)
This is related to the specific case of using using padding + clipToPadding="false" - in 4.4.x the footer is drawn outside of the view but clips to padding reveals it.
The solution I used was to set the footer over-scroll (android:overScrollFooter) to transparent which somehow works...
My final solution (note that android:footerDividersEnabled is kept for back-compatibility):
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin"
android:divider="#color/divider"
android:dividerHeight="1px"
android:clipToPadding="false"
android:scrollbarStyle="outsideInset"
android:overScrollFooter="#android:color/transparent"
android:footerDividersEnabled="false"
/>
tested on a HTC One X running 4.1.1, a Nexus 5 running 4.4.4 and a Samsung Galaxy S5 running 4.4.2 (thanks to #Dallas187). Seems to be working Lollipop too. (thanks to commenters!)

If you want to do this by code it's:
listView.setFooterDividersEnabled(false);
and if you're using a ListFragment you can get the listview by:
listFragment.getListView().setFooterDividersEnabled(false);
Only commented because this comes up as #1 in google

It seems below line does not work on lollypop device.
listView.setFooterDividersEnabled(false);
So need to use this below code to remove divider after last item in the list.
listView.setOverscrollFooter(new ColorDrawable(Color.TRANSPARENT));

Use background = #android:color/transparent. Works perfectly. You can still use the background of your row layout

Related

?android:attr/actionBarSize not working in only one device. Why?

Android experience level: Novice.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?android:attr/actionBarSize"
android:padding="10dp"
android:fillViewport="false">
I have applied top margin to the ScrollView which is the height of actionBar. That works well in two of my physical devices properly but not in one. Why the one device does not utilize the value?
Screenshots attached.
Lenovo A7000 with Marshmallow 6.0 Stock ROM:
Below the action bar, one or two lines are not visible. Probably behind the actionBar.
HTC phone and Samsung tablet: The text appears fine.
Try changing attribute value to ?attr/actionBarSize rather than using ?android:attr/actionBarSize

Android Ice Cream Sandwich: why ListView items remain selected by default?

I'm experiencing a weird and apparently undocumented issue on Android ICS. This is the xml code of my listview:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:focusable="false"
android:listSelector="#drawable/cell_selected_small"
android:descendantFocusability="afterDescendants" />
On Android 2.2 (tested on multiple devices) the listview selection is cleared right after the touch on it ends. I think this is the correct behavior.
On Android 4.0 and above, the listview selection stays selected, even if the onListItemClick() pushes a new Activity on the stack and then the back button is pressed. If then I scroll the listview for a while, the selection disappears after an apparently random amount of time.
Did any of you experience the same issue? Thanks!
Yes, it's a weird issue...set one property of your listview to get through this.
android:choiceMode="singleChoice"
Hope this will help you out..:-)
Not entirly sure but I set targert_sdk in my manifest back to 10 and things are OK so I went and looked at the compatibilty stuff in the documnetation. The API 11 list inclueds the line.
• GridView and ListView will use View.setActivated for selected items if they do not implement Checkable.
Whish I think is the relervant. I had
android:choiceMode="singleChoice"
in my xml and changed it to
android:choiceMode="none"
This looks to of got things back to what I want.

Android Header and Footer highlights when hit top or bottom of list

Is there a way to not let this happen? It's quite ugly aesthetically.
That's not a bug. That's a feature!
If you want to disable it, try calling:
listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
Unfortunately, it apparently doesn't work on all devices. (See, for example, here.)
Add one of these attributes to your list view in your layout file.
<ListView
android:overScrollHeader="#null"
android:overScrollFooter="#null" />
or
<ListView android:overScrollMode="never" />
Force setting a background color to the list item solves the highlighting issue.

Android: How to add a vertical progress bar to a home screen widget?

I need to put a vertical scroll bar in a home screen widget, and after searching many times, I can't find a convenient solution that works on API3 and above!
I tried many solutions:
- using bitmap created at run-time, but on some displays it never reach 100%
- a patch9 bitmap, but the scroll bar display gets completely messed up when the progress is near 0.
- using the addView() with 100 existing layout and it works great, except it's only available since API7!
- including all 100 layouts and showing only one at a time, work fine, but what a mess to include those in my 8 different widget layouts!
I tried to use the weight programmatically but it's not possible either, any other solution to resize a view based on a %?
Here is one progress bar layout I currently use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="#drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
Only solution I found so far is to have all the possible progress levels ready to use in various Xml layout files.
On Android API < 7, all those need to be included in a single xml layout and shown/hidden at run-time, while on Android API >= 7, one can actually use addRemoteView() to include the desired layout in a much more efficient way!
You should use ScrollView! You must place this within a layout. By default, scrollview is for Vertical Scroll. If you want horizontal scroll you must specify HorizontalScrollView. Hope this helps

dividers between TabWidgets

Is the android:divider attribute under the TabWidget working? I tried the Tab Layout tutorial from android just to test (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and set the android:divider to some image (for now I used the android vertical scrollbar as the drawable to really emphasize if its getting picked up (copied it from frameworks), but when I ran it on the emulator, it doesn't appear to be working. According to the docs, the TabWidget does seem to support this attribute: "Drawable used to draw the divider between tabs."
Can anyone help? I am using a nine-patched drawable as my divider image drawable.
MB
It doesn't look like the divider attribute is available anymore for TabWidget. One way to add a custom divider is to set it programmatically:
mTabHost.getTabWidget().setDividerDrawable(R.drawable.divider_vertical_dark);
Make sure however, you call this before you set the content of the tabs. It would crash on me if I called it after.
I had the problem in ICS, where divider was visible. None of the solutions worked except for the following.
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:fadingEdge="none"
android:showDividers="none" >
</TabWidget>
Key line was android:showDividers="none"
I had this issue and solved it with the following code
tabHost1.getTabWidget().setDividerDrawable(R.drawable.example1);
if(Build.VERSION.SDK_INT >= 11)
tabHost1.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE);
For api levels below 11, it worked with the first line. For 11 and higher I included this to get this working. setShowDividers is added in linearlayout from api level 11. Hope this helps someone
Having the same issue myself. I only see the problem in Ice Cream Sandwich (ICS / 4.0.x). In android 1.6 - 2.3.4 there is no issue, dividers show up properly when setting a drawable in code, or in the xml layout.
I've tried just about everything I can think of to fix it but nothing works, including Josh's answer above :( though I have noticed that when setting any drawable as the divider, it will take up the space between tabs as if there was a drawable there, but it's just not visible.
Hopefully that gives someone else a hint as to what could be happening..?
I removed divider line from tabbar with use of below magical lines.
mTabHost.getTabWidget().setDividerDrawable(null);
OR
mTabHost.getTabWidget().setDividerDrawable(R.Color.transperant);

Categories

Resources