【发布时间】:2023-03-23 09:33:02
【问题描述】:
【问题讨论】:
标签: android
【问题讨论】:
标签: android
创建微调器时,您可以为显示分配两个不同的模板。一个用于选择,一个用于下拉。
它在微调器的数据适配器中设置。这是我们使用的实际代码:
_spinDestination = (Spinner) findViewById(R.id.spinDestination);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.custom_spinner
, OrderDestRerouteDao.getList(_OrderDAO.getID(), _OrderDAO.getDestinationId()));
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
_spinDestination.setAdapter(adapter);
dropdownviewresource 就是这里要注意的。它控制下拉菜单的外观。
现在在您的页面布局中,将这些标签添加到您的微调器:
android:dropDownHorizontalOffset = "?"
android:dropDownVerticalOffset = "?"
在哪里? = 一个偏移量(例如:50dp)
布局更改将抵消您的下拉菜单。要获得它的任何其他样式(例如宽度),您需要为其自定义模板。
根据要求,这是我的微调器的完整 xml。
<?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"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/corner_shape"
android:orientation="vertical">
<TextView
android:id="@+id/tvCaption"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="-5dp"
android:background="@drawable/upper_corner"
android:gravity="center"
android:text="@string/heading_order_reroute_page_title"
android:textColor="@android:color/white"
android:textSize="@dimen/heading_text_size"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/label_current_destination"
android:textSize="@dimen/caption_text_size"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star"
android:visibility="invisible"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvCurrentDestination"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_weight="3"
android:focusable="false"
android:gravity="start|center_vertical"
android:paddingStart="10dp"
android:textSize="@dimen/caption_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:gravity="center_vertical"
android:text="@string/label_new_destination"
android:textSize="@dimen/caption_text_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/spinDestination"
style="@android:style/Widget.Spinner"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:dropDownHorizontalOffset = "?"
android:dropDownVerticalOffset = "?"
android:background="@drawable/bg_edit_text"
android:gravity="start|center_vertical"
android:paddingStart="10dp"
android:spinnerMode="dropdown" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:gravity="center_vertical"
android:text="@string/label_reroute_notes"
android:textSize="@dimen/caption_text_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_weight="0.1"
android:contentDescription="@drawable/star"
android:src="@drawable/star" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etRerouteNotes"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="5dp"
android:background="@drawable/bg_edit_text"
android:gravity="top|start"
android:paddingStart="10dp"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:textSize="@dimen/edit_text_size" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnReroute"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/btn_forward"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/btn_complete_order_reroute_caption"
android:textColor="@android:color/white"
android:textSize="@dimen/button_text_size"
android:textStyle="bold" />
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/btn_reject"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="@string/btn_cancel_caption"
android:textColor="@android:color/white"
android:textSize="@dimen/button_text_size"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
【讨论】: