微调器宽度与微调器项目宽度不匹配 [英] spinner width does not matches with spinner item width

查看:61
本文介绍了微调器宽度与微调器项目宽度不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用特定宽度(如400dp)作为DropDown项目的宽度,而spinner宽度则正确匹配.

When I use specific width like 400dp for the DropDown item's width and spinner width it matches properly.

但是当我将match_parent用于spinnercustom_spinner_item宽度时,它不匹配吗?图片可能会给出一个想法 我的代码有什么问题?我想使用match_parent设置相同的宽度吗?

But When I am using match_parent for the spinner and custom_spinner_item width it does not match? Image may give an idea What is wrong with my code? I want the same width using match_parent?

这是我的自定义custom_spinner_item

<?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="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/textView"
        android:layout_width="400dp"            // width
        android:layout_height="30dp"
        android:textSize="18dp"
        android:text="wallets"
        android:layout_marginLeft="5dp"
        android:paddingLeft="5dp"
        android:background="#FFFFFF"
        android:textColor="#282727"/>
    <View
        android:layout_width="400dp"
        android:layout_height="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#8e8c8c"/>
</LinearLayout>

我的片段

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/appbackground"
    android:paddingRight="5dp"
    android:paddingLeft="5dp"
    android:paddingTop="5dp">   

    // some code

   <LinearLayout
        android:id="@+id/dropDownLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/zxing_roundedbgwhite"
        android:orientation="vertical">
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="400dp"        // width
            android:layout_height="35dp"
            android:dropDownWidth="400dp"       // width
            android:spinnerMode="dropdown" />
    </LinearLayout>

    // some code

</LinearLayout>

推荐答案

最好的方法是通过给出

android:background="@null"

Spinner

因此该项目将占用Spinner

然后将箭头放在ImageView中,并与Spinner

Then put down arrow in a ImageView and align to right of Spinner

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:background="@null"
        android:layout_height="35dp"
        android:dropDownWidth="match_parent"
        android:spinnerMode="dropdown" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/spinner1"
        android:layout_alignRight="@+id/spinner1" 
        android:src="@drawable/arrow_down"
        android:layout_alignTop="@id/spinner1"
        android:layout_alignBottom="@+id/spinner1"/>
</RelativeLayout>

这篇关于微调器宽度与微调器项目宽度不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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