3

スピナー コントロールを複製しようとしています (理由は聞かないでください)。仕切りに苦労しています。イメージビューの左側に仕切りを追加するまで、偽のスピナーは問題なく見えます。仕切りを追加すると、その高さが画面の残りの部分を埋めます。誰かがこれを説明できますか?

次のxml:

.......

        <Spinner 
            android:id="@+id/equipment_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"/>
            <ImageView
                android:id="@+id/spinner_arrow"
                android:layout_width="45sp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/spinner_arrow"/>
        </RelativeLayout>
    </LinearLayout>    
</ScrollView>

次の画面が生成されます。

ここに画像の説明を入力

仕切りを追加すると、xml は次のようになります。

        <Spinner 
            android:id="@+id/equipment_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"/>
            <ImageView
                android:id="@+id/spinner_arrow"
                android:layout_width="45sp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:src="@drawable/spinner_arrow"/>
            <View
                android:background="#e7ebe7"
                android:layout_width="1dip"
                android:layout_height="fill_parent"
                android:layout_toLeftOf="@id/spinner_arrow"/>
        </RelativeLayout>
    </LinearLayout>    
</ScrollView>

次の画面が表示されます。

ここに画像の説明を入力 ここに画像の説明を入力 誰かが私がここで間違っていることを見つけることができますか? ...

4

2 に答える 2

2

複数のビューを使用する代わりに、これには 9 パッチ イメージを使用する必要があります。それがデフォルトのスピナーの機能です。新しいスピナーを作成する理由はわかりませんが、ビジュアルを同じに保っている場合は、組み込みの画像を再利用できます。

android.R.layout.simple_spinner_item再利用できる TextView レイアウトです。または、背景を直接取得することもできます。android.R.drawable.btn_dropdownこれは、各状態のビットマップを使用して描画可能な XML セレクターです。詳細については、Android ソース コードを参照してください。

于 2011-08-09T22:53:00.933 に答える
1

相対レイアウトの残りの部分を塗りつぶす親を塗りつぶすように高さを設定しました。次のように、ボタンまたはimageview内にビューを配置してみましたか。

<Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true">
        <View
            android:background="#e7ebe7"
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_toLeftOf="@id/spinner_arrow"/>
</Button>
        <ImageView
            android:id="@+id/spinner_arrow"
            android:layout_width="45sp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/spinner_arrow"/>
    </RelativeLayout>

また

<Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"/>
        <ImageView
            android:id="@+id/spinner_arrow"
            android:layout_width="45sp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/spinner_arrow">
            <View
            android:background="#e7ebe7"
            android:layout_width="1dip"
            android:layout_height="fill_parent"
            android:layout_toLeftOf="@id/spinner_arrow"/>
</ImageView>
    </RelativeLayout>

これが機能しない場合は、相対レイアウトの高さを10ディップなどの固定量に設定するか、スピナーの大きさを設定してみてください...いくつかの異なるサイズを試す必要がある場合があります。相対レイアウトをラップコンテンツとして残さないでください。

于 2011-08-09T22:14:05.987 に答える