I am creating custom spinner with custom array adapter.To show the spinner header title I am inflating different layout for the first position
public View getDropDownView(int aPosition, View aConvertView, ViewGroup aParent) {
View v = null;
if (aPosition == 0) {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.spinner_dropdown_header, aParent, false);
TextView tv = (TextView) v.findViewById(R.id.spinner_header_text);
tv.setText(getItem(aPosition));
} else {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.spinner_item_dropdown, aParent, false);
TextView tv = (TextView) v.findViewById(R.id.spinner_text);
tv.setText(getItem(aPosition));
}
return v;
}
Layout for spinner activity:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:padding="15dp">
// Other form controls
<Spinner
android:id="@+id/spinner_origin_sort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="@drawable/spinner_border"
android:paddingBottom="5dp"
android:spinnerMode="dialog"></Spinner>
//Other form controls
</LinearLayout>
Layout for spinner item(spinner_item_dropdown):
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/text_color"
android:textSize="16sp"
android:text="123"
android:textAlignment="center"/>
Layout for spinner dropdown header(spinner_dropdown_header.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/text_color"
android:gravity="center">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textAlignment="center"/>
</LinearLayout>
As highlighted The view is having some extra white space at the top and bottom.Expected output is spinner downdown without white strip at top and bottom.I have not applied any padding and margin for the spinner items.How this issue can be resolved?