微调器宽度与微调器项目宽度不匹配
spinner width does not matches with spinner item width
当我对 DropDown 项目的宽度使用 400dp
和 spinner
等特定宽度时,它会正确匹配。
但是当我使用 match_parent
作为 spinner
和 custom_spinner_item
宽度时它不匹配?图片可能会给出一个想法
我的代码有什么问题?我想要使用 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>
最好的方法是通过给出
来隐藏 Spinner
的向下箭头
android:background="@null"
到Spinner
因此该项目将占据整个 space 的 Spinner
然后在 ImageView
中放置箭头并对齐到 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>
当我对 DropDown 项目的宽度使用 400dp
和 spinner
等特定宽度时,它会正确匹配。
但是当我使用 match_parent
作为 spinner
和 custom_spinner_item
宽度时它不匹配?图片可能会给出一个想法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>
最好的方法是通过给出
来隐藏Spinner
的向下箭头
android:background="@null"
到Spinner
因此该项目将占据整个 space 的 Spinner
然后在 ImageView
中放置箭头并对齐到 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>