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

これを追加してみてください

android:layout_toRightOf="@+id/textview_spinner1 

また、違いが生じるかどうかを確認するために、以下を追加することもできます

android:layout_below 

そしてそれがどうなるか教えてください:)

于 2012-08-31T15:03:55.407 に答える
1

Java コードで (android.R.layout.simple_spinner_dropdown_item) を試すことができます。これの代わりに (com.Orange.R.layout.multiline_spinner_dropdown_item) これがお役に立てば幸いです。

于 2012-09-10T01:50:09.987 に答える
1

スピナー内の項目は同じ行に配置する必要があるため、水平レイアウトを使用しています!

問題は、多くのテキストを狭い領域に押し込もうとしていることです。ただし、次の 2 つのオプションがあります。

最初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 に答える