问个安卓中控件布局的问题:如何实现某个控件,与上一行的末端右对齐?

xadave 2016-09-01 11:49:43
安卓layout,主框架是个垂直的<LinearLayout>。其中某行是水平的<LinearLayout>。
接下来的一行是一个 Spinner, 如何让这个spinner,与上行的末端右对齐呢?

谢谢!

现有layout大致如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout
android:id ="@+id/viewPage1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout android:orientation="horizontal"

android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/src_amount1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:inputType="number"
android:imeOptions="actionDone"
android:text="1"
android:ems="4"
android:maxLength="4"/>

<TextView
android:text="@string/label_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>

<EditText
android:id="@+id/src_amount2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:inputType="number"
android:imeOptions="actionDone"
android:text="1"
android:ems="3"
android:maxLength="2"/>

<TextView
android:text="@string/label_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>

</LinearLayout>


<Spinner
android:id="@+id/my_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20sp"
android:drawSelectorOnTop="true">
</Spinner>

</LinearLayout>

</LinearLayout>
...全文
248 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiaoranak 2016-09-01
  • 打赏
  • 举报
回复
设置weight
xiaohuh421 2016-09-01
  • 打赏
  • 举报
回复
还有一种方法. 把你的linerlayout和spiner都到一个垂直布局的linerlayout中, 然后spiner的layout_gravity指定为右对齐
zhang106209 2016-09-01
  • 打赏
  • 举报
回复
相对布局容易实现
麦田捕手 2016-09-01
  • 打赏
  • 举报
回复
利用相对布局容易实现
香辣小龙人 2016-09-01
  • 打赏
  • 举报
回复
把Spinner放在一个RelativeLayout中,设置Spinner的属性layout_alignParentRight="true"
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Spinner
            android:id="@+id/my_spinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20sp"
            android:drawSelectorOnTop="true"
            android:layout_alignParentRight="true"
            >
        </Spinner>

    </RelativeLayout>
足球中国 2016-09-01
  • 打赏
  • 举报
回复
固定一下尺寸吧。这样比较简单。
悦奇 2016-09-01
  • 打赏
  • 举报
回复
可以利用相对布局啊

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧