Android的布局对齐问题 [英] Android Layout Alignment Issue

查看:133
本文介绍了Android的布局对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到正确的XML来定义在一个单独的线三个项目的布局如下:

I am trying to find the correct xml to define a layout of three items on a single 'line' as follows :


  • 按钮(在屏幕上左对齐)与文本'preV' - 包装上下文

  • 的TextView(中心对齐)与屏幕的标题 - 固定的200像素大小

  • 按钮(在屏幕上右对齐)与文本下一步 - WRAP_CONTENT

似乎无法得到它的工作,除非我用绝对的布局,我宁愿不要。
我已经尝试(好像每个选项)重力/ layout_gravity和嵌入式LinearLayouts ...

Just cannot seem to get it working unless I use absolute layout which I'd rather not. I have experimented (seems like every option) with gravity/layout_gravity and embedded LinearLayouts...

我想问题是 - 我可以右对齐一项,左对齐另一个与中心对齐另一都在同一的LinearLayout行

I guess the question is - can I right align one item, left align another and center align another all on the same LinearLayout 'line'

谢谢.. KJ

推荐答案

在这种情况下,你最好使用 RelativeLayout的如下:

In that case you better use RelativeLayout as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/btn_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Left" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/btn_left"
        android:layout_alignTop="@id/btn_left"
        android:text="In the center" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Right" />
</RelativeLayout>

顺便说一句......这不是推荐给精确的尺寸,以你的观点。而是使用类似 FILL_PARENT 相关事宜wrap_layout 等等。

这篇关于Android的布局对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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