I made a ListView in Android with some arbitrary elements. Row layout is inflated from XML file. Everything works fine but there is an extra margin bottom added to each row by default which i never mentioned anywhere.
Intentionally i set ListView background as green and row background as blue and RelativeLayout background as red. The result being there is a 1/1.5 DP margin bottom applied to each row.
Here the border with green color is actually the background color of ListView which indicates there is some gap between two rows.
Is this an intended behavior in android ListView if so why they add margin bottom automatically to rows ? And how to remove/overcome this behavior ?
Thank You, Have a nice day <3
Screenshot -
MainActivity.java
package com.xxx.abcd;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] num = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"};
ListView lv = (ListView) findViewById(R.id.lv);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, R.layout.row, num);
lv.setAdapter(arrayAdapter);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
tools:context="com.xxx.abcd.MainActivity">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00">
</ListView>
</RelativeLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:background="#214181"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:padding="10dp">
</TextView>