4

我有一个看起来非常丑陋的微调器,如下所示: 这是我的形象

当我点击它看起来好一点: 这是我的形象

但是,在默认情况下,它甚至看起来都不像一个微调器。知道如何改善它的外观吗?

这是代码:

adapter=new SpinAdapter(this,com.Orange.R.layout.spinnerrowlist,spinnerInfo);
adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item);
previousVisitCommentsSpinner.setAdapter(adapter);

spinnerrowlist.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="#FFFFFF"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textview_spinner1"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:layout_alignParentLeft="true"
        android:textColor="@drawable/textorange_selected" />

    <TextView
        android:id="@+id/textview_spinner2"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/textview_spinner1"
        android:paddingLeft="5dp"
        android:textColor="@drawable/textorange_selected" />

    <TextView
        android:id="@+id/textview_spinner3"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingLeft="5dp"
        android:textColor="@drawable/textorange_selected" />

</RelativeLayout>

这是微调器:

<Spinner
    android:id="@+id/previousVisitComments"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_below="@+id/previousvisit"
    android:layout_marginTop="15dp"
    android:background="@drawable/spinner_selector"
    android:textColor="@color/medium_orange"
    android:textAppearance="?android:attr/textAppearanceMedium"
    />

微调器中的项目应该在同一行,这就是我使用水平布局的原因! 谢谢您的回答!

4

3 回答 3

1

微调器中的项目应该在同一行,这就是我使用水平布局的原因!

问题是您正试图将大量文​​本压缩到一个狭窄的区域。但是,您有两种选择:

首先使用你所拥有的,只需将layout_toLeftOf属性添加到textview_spinner2

<TextView
    android:id="@+id/textview_spinner2"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_toLeftOf="@+id/textview_spinner3"
    android:layout_toRightOf="@+id/textview_spinner1"
    android:paddingLeft="5dp" />

您还说您正在使用a horizontal layout但 RelativeLayout 没有属性orientation,所以这一行什么都不做:

android:orientation="horizontal"

子元素的组织由各个属性决定,例如:layout_toLeftOflayout_toRightOflayout_above等。

其次,如果您的 RelativeLayout 表现得不守规矩,并且您有一个像这样的简单布局,您可以随时切换到 LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp" >

    <TextView
        android:id="@+id/textview_spinner1"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:textColor="@drawable/textorange_selected" />

    <TextView
        android:id="@+id/textview_spinner2"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingLeft="5dp"
        android:textColor="@drawable/textorange_selected" />

    <TextView
        android:id="@+id/textview_spinner3"
        style="?android:attr/spinnerItemStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:paddingLeft="5dp"
        android:textColor="@drawable/textorange_selected" />

</LinearLayout>

现在 Spinner 中的所有列都没有重叠。

于 2012-08-31T15:25:41.277 回答
1

您可以在 Java 代码中尝试 (android.R.layout.simple_spinner_dropdown_item)。而不是这个(com.Orange.R.layout.multiline_spinner_dropdown_item)希望这会有所帮助。

于 2012-09-10T01:50:09.987 回答
1

尝试添加这个

android:layout_toRightOf="@+id/textview_spinner1 

您还可以添加以下内容以查看是否有所不同

android:layout_below 

让我知道情况如何:)

于 2012-08-31T15:03:55.407 回答