android相关布局示例

如果需要实现如下内容的布局:

image

一般会采用相关布局,即RelativeLayout。

布局文件类似这样:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:padding="10px" xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:text="填写内容:" android:id="@+id/TextView01"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <EditText android:layout_width="fill_parent"
        android:layout_below="@+id/TextView01" android:id="@+id/EditText01"
        android:layout_height="wrap_content" android:text=""></EditText>
    <Button android:layout_width="wrap_content" android:text="确定"
        android:layout_below="@+id/EditText01" android:layout_height="wrap_content"
        android:layout_alignParentRight="true" android:layout_marginLeft="10px"
        android:id="@+id/Button01"></Button>
    <Button android:layout_width="wrap_content" android:text="取消"
        android:layout_toLeftOf="@id/Button01"  android:layout_alignTop="@id/Button01" android:layout_below="@+id/EditText01"
        android:layout_height="wrap_content" android:id="@+id/Button02"></Button>

 

布局文件中,需要定义某个窗口组件相对于其他组件的相对位置,比如下面,比如右面等等。

源代码见:

http://easymorse.googlecode.com/svn/tags/android.layout.demo_1.3/

PDF格式創作    发送文章为PDF   

1 Comment to “android相关布局示例”

  • Android相关布局示例 | 第三极 — 2010年12月23日 @ 11:11

  • 这篇文章上的评论的 RSS feed TrackBack URI

    Leave a Reply