如何在LinearLayout中向右移动微调器? [英] How to move spinner in LinearLayout to right?

查看:146
本文介绍了如何在LinearLayout中向右移动微调器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

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

当前看起来像这样:

我想将Spinner移到LinearLayout的右侧.我尝试使用:

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

android:gravity="right"

android:gravity="end"

android:layout_gravity="right"

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

推荐答案

我建议对此逻辑使用RelativeLayout:

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

通过父路线属性(即layout_alignParentLeft,layout_alignParentRight),您可以将组件放置到首选位置

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

这篇关于如何在LinearLayout中向右移动微调器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆