Adding a row with bigger height to Spinner adds padding to bottom

十年热恋 提交于 2019-12-24 20:23:18

问题


I would like to build this dropdown layout:

To be able to add the top and bottom padding of 8dp I used the following code:

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) 
{
    if (convertView == null) {
        if (position == 0) {
            convertView = inflater.inflate(R.layout.spinner_row_top, null);
        } else if (position == (getCount() - 1)) {
            convertView = inflater.inflate(R.layout.spinner_row_bottom, null);
        } else
            convertView = inflater.inflate(R.layout.spinner_row, null);
    }

    TextView title =(TextView) convertView.findViewById(R.id.spinner_row_textview);
    title.setText(data.get(position));
    return convertView;
}

However this adds a padding to the bottom of the Spinner. I guess the padding is added because the Spinner calculates it's dropdown height based on the first element and since the following elements have lower heights a padding remains at the bottom.

EDIT: Here's the xml of the Spinner row:

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:gravity="center_vertical"
    android:minHeight="48dp"
    android:orientation="horizontal"
    android:paddingBottom="20dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp">

    <TextView
        android:id="@+id/spinner_row_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:padding="0dp"
        android:textSize="16sp"/>

   </LinearLayout>

The top and bottom xml files have their minHeight and layout_height set to 56dp and have a padding of 8 at the top/bottom.

And here's the spinner:

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:paddingRight="0dp"/>

Any ideas how I could remove the bottom padding?

来源:https://stackoverflow.com/questions/47754037/adding-a-row-with-bigger-height-to-spinner-adds-padding-to-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!