简体   繁体   English

Android自定义微调器文本重叠右图标

[英]Android custom spinner text overlapping right icon

I'm using custom design for my spinner but the text got overlap on the right icon of the spinner. 我正在为旋转器使用自定义设计,但是文本在旋转器的右侧图标上重叠了。 Please have a look on the attached image. 请看附件图片。

<Spinner
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:spinnerMode="dialog"
                android:background="@drawable/spinner_bg"
                android:id="@+id/mySpinner"
                android:prompt="Testing"
                android:layout_marginTop="8dp" />

spinner_bg.xml : spinner_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <layer-list>
        <item>
            <shape>
                <gradient
                    android:startColor="#6e95bd"
                    android:endColor="#517295"
                    android:angle="270" />
                <stroke
                    android:width="1dp"
                    android:color="#000" />
                <corners
                    android:radius="50dp" />
            </shape>
        </item>
        <item>
            <bitmap android:gravity="right|center_vertical"  android:src="@mipmap/ic_spinner_down"/>
        </item>
    </layer-list>
</item>
</selector>

结果:

Try using android:paddingRight="30dp" or more according to your icon. 尝试根据您的图标使用android:paddingRight="30dp"或更多。

<Spinner
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:spinnerMode="dialog"
   android:background="@drawable/spinner_bg"
   android:id="@+id/mySpinner"
   android:prompt="Testing"
   android:layout_marginTop="8dp"
   android:paddingRight="30dp" />

Since the background is set to the spinner, no matter what the width of the spinner is, it will always overlap that right icon, so the easiest way to achieve what you are trying to achieve is 由于背景设置为微调器,所以无论微调器的宽度是多少,它始终会与右侧图标重叠,因此实现您想要实现的最简单方法是

<LinearLayout
        android:layout_width="match_parent"
        android:background="@drawable/spinner_bg"
        android:layout_height="wrap_content">
    <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:spinnerMode="dialog"
            android:layout_gravity="left"
            android:gravity="left"
            android:background="@android:color/transparent"
            android:id="@+id/mySpinner"
            android:prompt="Testing"
            android:layout_marginTop="8dp" />
</LinearLayout>

Make custom adapter for spinner and set the layout of single row as below : 制作微调器的自定义适配器,并如下设置单行的布局:

 <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
       <TextView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:layout_gravity="left"/>
     <ImageView 
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:layout_gravity="right"/>
    </FrameLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM