Android 删除微调器中的间距

Android 删除微调器中的间距,android,spinner,Android,Spinner,我想将文本左对齐,就像图中所示的edittext一样。但是,Deafolt spinner包括该间距。所以,我想删除它以使文本向左对齐。有人知道怎么修吗 创建布局名称spinner\u text.xml。将此代码粘贴到其中: <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_

我想将文本左对齐,就像图中所示的edittext一样。但是,Deafolt spinner包括该间距。所以,我想删除它以使文本向左对齐。有人知道怎么修吗


创建布局名称
spinner\u text.xml
。将此代码粘贴到其中:

<TextView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="textStart"
android:gravity="start"
android:maxLines="1"
/>

然后编辑java代码。像这样更改Java适配器

ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this,
            R.layout.spinner_text,paths);
ArrayAdapter=新的ArrayAdapter(MainActivity.this,
R.布局.微调器(文本、路径);
(如上所述更改布局)

然后微调器文本将与文本对齐。
祝你好运。

只需在xml微调器布局中添加一些额外的负边距。不需要创建自定义文本视图布局

像这样:

<Spinner
    android:id="@+id/spinnerDistrict"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="-6dp"
    android:layout_marginBottom="@dimen/basic_margin_padding_min"
    android:layout_marginTop="@dimen/basic_margin_padding_min"
    android:spinnerMode="dropdown" />


就这样

是否要删除红色标记的空格?