2

カスタムスピナーを作成しましたが、サイズが希望どおりではありません。スピナーは、必要なリストの間隔を取得するために非常に大きくなります。スピナーボタンのサイズとは関係なく、スピナーの行のサイズを変更できるようにしたい。スピナーを薄くしてから、セクションの行の間隔を広くしたい。(下の画像を参照):

現在、スピナーの行のxmlは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:padding="5dip">
        <ImageView android:layout_width="32sp" android:src="@drawable/icon"
            android:id="@+id/spinnerimage" android:layout_height="32sp" />
        <TextView android:textSize="22sp" android:textStyle="bold" android:textColor="#000"
            android:layout_width="fill_parent" android:id="@+id/category"
            android:layout_height="fill_parent" android:paddingLeft="5sp" />
    </TableRow>
</TableLayout>

相対レイアウトを使用したかったのですが、テーブルレイアウトの方が少し間隔が広くなりました。高さを作成しようとすると、行のテキストとアイコンが切り取られます。main.xmlのスピナーは次のとおりです。

        <Spinner android:id="@+id/catspinner"
        android:layout_marginLeft="25dip" android:layout_marginRight="25dip"
        android:layout_width="fill_parent" android:layout_centerHorizontal="true"
        android:layout_height="wrap_content" android:prompt="@string/prompt"
        android:background="@drawable/yellow_btn"
        android:layout_centerVertical="true" android:drawSelectorOnTop="true" />

ここに画像の説明を入力してください

スピナーのサイズを標準のAndroidスピナー(右側)と同じにしたいのですが、現在、スピナーが大きくなり、行の間隔が小さすぎます。

何か案は??

4

3 に答える 3

7

アダプターを設定している間、adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); これはうまくいくはずだと言います...

于 2011-08-10T13:04:25.177 に答える
1

必要に応じて以下のコードを使用してください...

ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.Questions, R.layout.custom_spinner_list);
            adapter.setDropDownViewResource(R.layout.customer_spinner);
            spin.setAdapter(adapter);

custom_spinner_list.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="@+id/TextView01"
    android:id="@+id/TextView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:textColor="#000000">
</TextView>

customer_spinner.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="@+id/TextView01"
    android:id="@+id/TextView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:textColor="#000000"
    android:height="42dp"
    android:gravity="center_vertical"
    android:padding = "2dp">
</TextView>
于 2011-08-10T13:05:04.327 に答える
1

たぶんこれはかなり遅いですが、私は同様の問題に遭遇したので、とにかくこれを共有します。

スピナー自体にはビュー「simple_spinner_item」を使用し、ドロップダウンには「simple_spinner_dropdown_item」を使用する必要があります。

コードスニペットは次のとおりです。

Spinner spnCat = (Spinner) findViewById(R.id.idea_category);

Cursor c = myDBHelper.getCategories();
startManagingCursor(c);

if (c != null) {
    // use the simple_spinner_item view and text1
    SimpleCursorAdapter adapterCat = new SimpleCursorAdapter(this,
        android.R.layout.simple_spinner_item,
        c, 
        new String[] {c.getColumnName(1)}, 
        new int[] {android.R.id.text1});

    spnCat.setAdapter(adapterCat);

    // use the simple_spinner_dropdown_item
    adapterCat.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item);
}

お役に立てば幸いです。

于 2011-12-23T19:48:40.063 に答える