【发布时间】:2012-03-06 12:28:54
【问题描述】:
我使用自己的 ProjectSpinnerAdapter 创建了一个自定义微调器。我还有另一个类,它只是扩展了布局,但尚未实现,所以仍在使用标准微调器。
我似乎无法让我的自定义微调器以与标准微调器相同的方式对齐。
当项目的长度比表格单元格宽时,我也会遇到问题,如下所示。如果选项超过一定长度,有没有办法截断它们? - 这似乎不是解决此问题的正确方法,但我无法直接设置小部件的宽度,因为这是通过表格布局控制的。*
**已修复,请参阅更新*
截图
标准微调器与其旁边的 Button 完美对齐(它们都包含在同一个 TableRow 中)
布局
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1" >
<TableRow>
<Button
android:id="@+id/selectButton"
android:text="@string/show" />
<Spinner android:id="@+id/projectSpinner" />
</TableRow>
spinner_list_item.xml(使用 maxLength)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:maxLength="15"
android:gravity="center"/>
</LinearLayout>
更新
问题是微调器项目的布局,在我的自定义布局 spinner_list_item.xml 中,我指定了一个布局,我只需要 textview
spinner_list_item.xml(使用 maxLength)
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title_text_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:maxLength="15" />
【问题讨论】:
标签: android android-layout android-widget android-spinner