如何将Android Spinner下拉箭头更靠近其发射文本 [英] How to move the Android Spinner drop down arrow closer to it's emitting text

查看:288
本文介绍了如何将Android Spinner下拉箭头更靠近其发射文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将下拉箭头设置为更靠近Spinner中它的发射文本元素.如何做到这一点?

I need to set the drop down arrow closer to its emitting text element in Spinner. How can achieve this?

<Spinner android:id="@+id/spinner"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />

推荐答案

您可以通过在xml中定义自定义背景,然后从右侧设置箭头的边距来解决此问题.

You can fix this by defining a custom background in xml, and then setting the arrow's margin from the right side.

首先定义一个带有矩形背景的图层列表和一个箭头位图对象.您可以通过设置箭头的重力使箭头与右侧的中心对齐,并且可以通过android:"right"属性设置箭头的右边界将其向中心移动.请注意,这不会根据文本的长度动态地移动箭头,但是这应该是一个有用的第一步.

Start by defining a layer-list with a rectangle background and a bitmap object for your arrow. You can make the arrow align to the center on the right side by setting its gravity, and you can move it towards the center by setting its right margin via the android:"right" attribute. Note that this won't dynamically move the arrow based on the length of text, but it should be a helpful first step.

spinner_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/color_white" />
            <corners android:radius="2.5dp" />
        </shape>
    </item>
    <item android:right="64dp">
         <bitmap 
             android:gravity="right|center_vertical"  
             android:src="@drawable/ic_spinner" />
    </item>
</layer-list>

这篇关于如何将Android Spinner下拉箭头更靠近其发射文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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