2011-12-29 8 views
3

2つのスピナーを隣に置くと、この問題が発生します。ここではレイアウトXMLのフラグメントである:隣り合う2つのスピナー

... 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <Spinner 
     android:id="@+id/x" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|left" 
     android:layout_weight="1" /> 

    <Spinner 
     android:id="@+id/y" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|right" 
     android:layout_weight="1" /> 
</LinearLayout> 

<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <ListView 
     android:id="@+id/z" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:cacheColorHint="#FFFFFF" > 
    </ListView> 
... 
... 

ここでの結果である:

spinners

私は、多くの異なるものを試してみました。私は重力、重力、親をRelativeLayoutに変更しようとしましたが、結果は変わりません。

助けてください!

編集:

わかった。いくつかの冗長性が、問題を解決します。なぜこれが動作し、 "正常な方法"はありませんかわいい奇妙な。みんな助けてくれてありがとう。

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <Spinner 
     android:id="@+id/x" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 

     <Spinner 
      android:id="@+id/y" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" /> 
    </RelativeLayout> 
</LinearLayout> 
+0

問題を再現できません。次のようにアンドロイド:layout_gravity = "center_vertical"をスピナーに追加しました。お互いに隣り合う2つのスピナーを除いてすべてを剥がそうとしましたか?ルートと2つのスピナーのLinearLayoutは1つだけですか?また、Eclipseのプレビューと実際のデバイス/エミュレータでこの問題が発生していますか? –

答えて

0

私はその正確な問題を見たことがありませんが、私はあなたが両方の競合する可能性がその幅、と親を満たしていることがわかります。私はandroid:layout_width="0dip"と置き換えて、そのサイズを決定するためにウェイトを使用するすべての要素に対して、実際には等しくなるようにします。 RelativeLayoutで

+0

私はそれを変更しました。残念ながら助けてくれませんでした。この問題は景観にもあると付け加えておきます。 – Paul

+0

申し訳ありませんが、私は質問をupvoted、うまくいけばそれは応答を得るでしょう。 – Pyrodante

+0

ありがとうございます。私もそう願います。 – Paul

1

、あなたはandroid:layout_toRightOf="@+id/x"android:layout_alignTop="@+id/x"を使用することができます。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout> 
    <Spinner 
     android:id="@+id/x" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <Spinner 
     android:id="@+id/y" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/x" 
     android:layout_alignTop="@+id/x" /> 
</RelativeLayout> 

(彼らはあなたのスピナー内のテキストに影響を与えていないようでしたように私は、重力の定義を残してきた。)

+0

それを試してみてください。あなたが与えたソリューションを正確に使用すると、次のような結果が得られます。最初の(一番左の)スピナーが親を塗りつぶし、もう一方を画面から離します。さらに、ランドスケープに切り替えると例外が発生します。例外は、アンドロイドは "y"( "y"は2番目(最も右))のスピナーを見つけることができないと言います。 – Paul

+0

最初のスピナーの固定幅を設定しようとしました。それはうまくいった。しかし、今私は彼らが親の幅のちょうど50%をそれぞれ満たしているわけではありません。また、上記の例外はまだ存在します。 – Paul

-1

しかし、私はこのコードで何かが間違って見ることができませんが、私はwrap_contentの高さは自動的に上と左と右の両方のスピナーは画面の半分の幅のためのケースではないので、重力を設定する必要はないと思う。

ので使用:

<Spinner 
    android:id="@+id/x" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

<Spinner 
    android:id="@+id/y" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" /> 

+0

同じ問題。しかし、ありがとう。 – Paul

5

これが私のために正常に動作します:私のために働く

<LinearLayout 
    android:id="@+id/x" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2"> 
    <Spinner 
     android:id="@+id/s1" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
    <Spinner 
     android:id="@+id/s2" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
</LinearLayout> 
0

代替ソリューションを。

<LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:layout_marginTop="10dp" 
        android:orientation="horizontal" > 

        <Spinner 
         android:id="@+id/custSpinner" 
         style="@android:style/Widget.Spinner" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         /> 

        <Spinner 
         android:id="@+id/busSpinner" 
         style="@android:style/Widget.Spinner" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         /> 
       </LinearLayout> 
関連する問題