0

I have this horizontal Layout in a vertical Layout. Inside my horizontal Layout I have to views (Spinners) which I want to be displayed right to left.

The top image is what I'm getting right now. The bottom is what I expect. Very simple.

enter image description here I've been trying changing all attributes. Nothing seems to work. Changed gravity, layout_gravity...

And because I'm willing to use weight I can't use RelativeLayouts.

How should I fix this? Is there any solution that does not end up in messing with the arrangement and order of my XML and putting the first control after the 2nd one (I hate that)?

Is there something obvious that I don't know or am missing? Thanks a lot in advance.

<LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/tb3TxtPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="20dp"
android:text="price"
android:textAppearance="?android:attr/textAppearanceMedium"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" 
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:orientation="horizontal">

    <Spinner
    android:id="@+id/tb3SprPriceStartLimit"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_gravity="right"
    android:entries="@array/priceStartLimitArray" />


    <Spinner
    android:id="@+id/tb3SprPriceEndLimit"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_gravity="right"
    android:entries="@array/priceEndLimitArray" />
</LinearLayout>
Fatima
  • 869
  • 10
  • 35

2 Answers2

1

Just exchange the two Spinner's order that they appear.

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="right" 
  android:layout_marginRight="20dp"
  android:layout_marginLeft="20dp"
  android:orientation="horizontal">
  <-- the 1 -->
  <Spinner
  android:id="@+id/tb3SprPriceStartLimit"
  android:layout_weight="1"
  android:layout_width="0dp"
  android:layout_height="40dp"
  android:entries="@array/priceStartLimitArray" />

  <-- the 2 -->
  <Spinner
  android:id="@+id/tb3SprPriceEndLimit"
  android:layout_weight="1"
  android:layout_width="0dp"
  android:layout_height="40dp"
  android:entries="@array/priceEndLimitArray" />
</LinearLayout>

In addition, it is not useful to set layout_gravity=left or layout_gravity=right when the orientation is horizontal in LinearLayout.

zhenghuiyan
  • 324
  • 4
  • 10
0

try this:

Keep first the on which you want to be on right.... then left one.. gravity is only for allining the text

<Spinner
    android:id="@+id/tb3SprPriceEndLimit"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_gravity="right"
    android:entries="@array/priceEndLimitArray" />

<Spinner
    android:id="@+id/tb3SprPriceStartLimit"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_gravity="right"
    android:entries="@array/priceStartLimitArray" />
Siva
  • 9,043
  • 12
  • 40
  • 63
  • I suppose your answer is the most likely way to go. I tried it. But the 2 spinners are now gone and not seen anywhere on the screen. – Fatima May 25 '14 at 13:43
  • means those are not visible? – Siva May 25 '14 at 13:44
  • first write the code for spinner that need to be on 'right side' and then add above code. – Siva May 25 '14 at 13:46
  • I think my answer doesn't applies you..`android:layout_toLeftOf` applies to relative layout not linear layout – Siva May 25 '14 at 13:50
  • I think so too. And the disappearance turns out to be because of width=0. Which I have no choice but to use because I'm using width to have spinners occupy same space. – Fatima May 25 '14 at 13:52
  • I don't get it: "Keep first the on which you want to be on right.... then left one.." what should I do? – Fatima May 26 '14 at 08:56