Using View to add divider in listView
Why don't you try this approach for custom divider
you need to check the position of the cell
in your getView()
and accordingly you can from your code hide/show your custom divider
if(childPosition==0)//is first child
{
YOURDIVIDER.setVisibility(View.GONE);
}
else
{
YOURDIVIDER.setVisibility(View.VISIBLE);
}
you need to find your divider view for this, before doing this.
How to set width of ListView divider?
Make a 9 patch png that has transparent pixels on the left and right. For example, a 53x4 .9.png that has 25 transparent pixels either side (+ pixels to 9patch it) would stretch the 1 pixel out so there is 25 pixels either side of it.
How to assign padding to Listview item divider line
Use 'inset'.....
(list_divider.xml)
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="50dp"
android:insetRight="50dp" >
<shape>
<solid android:color="@color/orange" />
<corners android:radius="2.0dip" />
</shape>
</inset>
and in your list view add like this...
<ListView
android:dividerHeight="2dp"
android:divider="@drawable/list_divider"
...
/>
you can set the inset value as desired...
UPDATE
As pointed out by @Giulio Piancastelli , If the background of list container is different from background of list item then you may use 'layer-list'...
(list_divider.xml)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/list_background" />
</shape>
</item>
<item
android:left="10dp"
android:right="10dp">
<shape android:shape="rectangle" >
<solid android:color="@color/divider_color"/>
</shape>
</item>
</layer-list>
and in your list view add like this...
<ListView
android:dividerHeight="2dp"
android:divider="@drawable/list_divider"
...
/>
How do I remove the divider from a listview on android?
You can try android:divider="@null"
.
Listview divider margin
Inset is the way to go
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="15dp"
android:insetRight="15dp" >
<shape
android:shape="line" >
<stroke
android:dashGap="1dp"
android:dashWidth="1.5dp"
android:width="1dp"
android:color="#FF404040" />
<size android:height="3dp" />
</shape>
</inset>
Separator (divider) after last item of ListView
The answer is very simple: you should change android:layout_height="wrap_content"
to android:layout_height="match_parent"
in your ListView
.
You can probably guess why this happens.
Related Topics
How to Prevent a Service from Being Killed by Os
How to Do Http Authentication in Android
Android Webview Not Loading an Https Url
Audiorecord Object Not Initializing
Embedding Ads Within Recyclerview
Creating an Android Trial Application That Expires After a Fixed Time Period
Create Custom Notification, Android
Is There Any Reason to Use the Support.V4 Library in Android
How to Pass Integer from One Activity to Another
Recognizing Multiple Keywords Using Pocketsphinx
Out of Memory Error with Bitmap
Can't Create Handler Inside Thread Which Has Not Called Looper.Prepare()
How to Handle Cookies in Httpurlconnection Using Cookiemanager
How to Get Current Activity's Layout and Views via Adb
How to Save Geofire Coordinates Along with Other Items in Firebase Database
Export a Python Script to an Android Executable (.Apk) with Python-For-Android