[我有一个微调器,并且在api 27上进行测试后,微调器上会自动设置一个边距。
<Spinner
android:id="@+id/testspinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dropDownVerticalOffset="35dp"
android:gravity="end"/>
但是,在API 19设备上进行测试时,不再有余量。如何为AP 19和更低版本的设备增加边距?
我也尝试过将Spinner
更改为androidx.appcompat.widget.AppCompatSpinner
,但这不会增加边距。
将textView用于您的Select Role(选择角色)文本,并从微调框向左放置。最后,布局应如下所示。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Roll"
android:id="@+id/spinnerHeader"
android:layout_marginStart="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.appcompat.widget.AppCompatSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/spinnerHeader"
app:layout_constraintTop_toTopOf="@id/spinnerHeader"
android:layout_marginStart="15dp"
app:layout_constraintBottom_toBottomOf="@id/spinnerHeader"/>
</androidx.constraintlayout.widget.ConstraintLayout>