Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have code like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
>

<LinearLayout
    android:id="@+id/relativeLayoutforPRICE"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textView$_points_to_win"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Points to win"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Spinner
        android:id="@+id/spinner$_points_to_win"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>

Currently it looks like that:

enter image description here

I would like to move Spinner to the right side of the LinearLayout. I tried to use:

android:gravity="right"

and

android:gravity="end"

and

android:layout_gravity="right"

and

android:layout_gravity="end"

but it didn't help. Is there any other option to move it to the right? What's also important I want to keep parent layout as Linear (oriented vertically) and current layout as Linear (oriented horizontally).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
295 views
Welcome To Ask or Share your Answers For Others

1 Answer

I suggest to use RelativeLayout to this logic:

<RelativeLayout
    android:id="@+id/relativeLayoutforPRICE"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textView$_points_to_win"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Points to win"
        android:layout_alignParentLeft="true"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Spinner
        android:id="@+id/spinner$_points_to_win"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"/>

</RelativeLayout>

By parent alignments properties (i.e. layout_alignParentLeft, layout_alignParentRight) you can place components to prefered place


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...