Android的布局对齐问题 [英] Android Layout Alignment Issue
问题描述
我试图找到正确的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屋!