为什么我的旋转器不像个旋转器?

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"
    />

旋转框中的项目应在同一行上,这就是我使用水平布局的原因! 感谢您的回答!


1
关键在于 com.Orange.R.layout.spinnerrowlist,而不是下拉菜单。我现在看不到它;如果我有空的话,我会尝试稍后查看,但它试图将文本挤入一个小区域。 - Muz
3个回答

1
尝试添加这个。
android:layout_toRightOf="@+id/textview_spinner1 

你也可以添加以下内容,看看是否有所不同

android:layout_below 

让我知道进展如何 :)


1
“Spinner”中的项目应该在同一行上,这就是为什么我使用了水平布局的原因!
问题在于您试图将大量文本压缩到一个狭窄的区域中。但是您有两个选择:
首先,使用您已经拥有的,只需将“textview_spinner2”的“layout_toLeftOf”属性添加即可:
<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" />

另外,您说您正在使用水平布局,但是RelativeLayout没有属性方向,因此此行代码无效:

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中没有任何列重叠。


1
你可以在Java代码中尝试使用(android.R.layout.simple_spinner_dropdown_item)。而不是使用(com.Orange.R.layout.multiline_spinner_dropdown_item)。希望这能帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接