2011-08-09 10 views
3

私はスピナーコントロールを複製しようとしています(理由を聞かないでください)私は仕切りで苦労しています。偽のスピナーは、イメージビューの左側に仕切りを追加するまでうまく見えます。ディバイダを追加すると、画面の残りの部分が高さになります。誰かがこれを説明できますか?私は、分周器を追加すると、アンドロイド:子ビューのfill_parentが画面を塗りつぶす

enter image description here

次の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> 

enter image description here enter image description here を誰も私が間違ってここにやって見つけることができます...

+0

私はあなたの質問に投票しました。誰かが同じことをした場合、画像を投稿するのに十分な担当者がいるでしょう。 – Squonk

+0

投票してください、画像を投稿してください – Rob

答えて

2

9パッチイメージf複数のビューを使用する代わりに、それがデフォルトのSpinnerの機能です。なぜ新しいスピナーを作成したいのかわかりませんが、ビジュアルを同じにしておけば、組み込みのイメージを再利用するだけで済みます。

android.R.layout.simple_spinner_itemは、再利用できるTextViewレイアウトです。または、背景を直接取ることができます:android.R.drawable.btn_dropdownは、各セレクタのビットマップを使ってXMLセレクタ描画可能です。詳細は、Androidのソースコードで入手できます。

+0

良い提案...私はセレクタを使用して戻って、そのアプローチについて忘れてしまった...時には方向に向かい、別の考え方を忘れる...リダイレクトのおかげで... btw、私はこれをやっている一緒に複数選択のスピナーをステッチ...ほぼそこに...ありがとう – user806821

1

あなたは親を埋めるために設定し、高さを持っています?これは相対レイアウトの残りの部分を満たします。

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

OR

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

このdoesntの仕事は、一定量のように相対的なレイアウトの高さを設定してみてください場合:あなたは、次のようにボタンやImageViewの内面図を入れてみました10ディップまたはスピンナーは大きいですが...あなたは異なるサイズのファイルを試す必要があるかもしれませんが、ラップコンテンツとしてrelativelayoutを残さないでください

+0

その上から下に伸びるはずの単一のピクセルワイド行...幅は問題ではありません...その高さのfill_parent ...私はfill_parentがちょうどすぐに親コンテナ – user806821

+0

...このケースではfill_parentに設定されていない相対レイアウト – user806821

+0

ボタンにイメージビューを置くとは思いません...ボタンはビューグループではありません...試してみます。 – user806821

関連する問題