Android Spinner:删除文本和下拉图标之间的多余空白 [英] Android Spinner: Remove Extra White Space Between Text and Dropdown Icon

查看:221
本文介绍了Android Spinner:删除文本和下拉图标之间的多余空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个微调框,默认情况下,文本和下拉图标之间有多余的空白,我真的不喜欢,想删除它.

I have a spinner and by default there is extra white-space between text and dropdown icon which I really don't like and wanna remove it.

尝试在网上搜索,但没有得到任何可以帮助我的信息.这里有人早点做过吗?

Tried searching over the web but did not get anything which could help me. Anybody here who has done it earlier?

推荐答案

在和Spinner玩完之后,我自己做了.这是效果很好的解决方案.

I did it myself after playing with Spinner. Here is the solution which worked pretty well.

首先使用您选择的指标图像创建一个下拉菜单.

First create a Dropdown with indicator image of your choice.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape
        android:shape="rectangle"/>
</item>
<item
    android:width="24dp"
    android:height="24dp"
    android:gravity="right|center_vertical">
    <bitmap
        android:src="@drawable/ic_dropdown"
        android:tint="@color/colorPrimaryDark"/>
</item></layer-list>

然后将其分配给Spinner的背景.

Then assign it to the background of Spinner.

<Spinner
        android:id="@+id/basket_spinner_item_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:spinnerMode="dropdown"
        android:padding="0dp"
        android:background="@drawable/ic_spinner_dropdown"/>

现在,根据需要调整微调器项目的填充和对齐方式.

Now, adjust the padding and alignment of spinner item as per your requirement.

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/simple_spinner_text_quantity"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="25dp"
android:gravity="right"
android:textAlignment="gravity"/>

这篇关于Android Spinner:删除文本和下拉图标之间的多余空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆