android 布局随笔

来源:互联网 发布:淘宝上的epiphone 编辑:程序博客网 时间:2024/06/04 18:53

先看一下登录界面。

本文章就是给初学者一个例子。

本例子使用RelativeLayout布局标签

 

现在上代码

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="fill_parent" 4     android:layout_height="fill_parent" 5     android:orientation="vertical" 6     android:padding="10px"> 7          8         <TextView android:layout_width="wrap_content" 9                       android:layout_height="wrap_content"10                       android:id="@+id/tx_username"11                       android:text="@string/tx_username"/>12         13         <EditText android:layout_width="fill_parent"14                   android:layout_height="wrap_content"15                   android:background="@android:drawable/editbox_background"16                   android:layout_below="@id/tx_username"17                   android:id="@+id/UserName"/>18         19         <TextView android:layout_width="wrap_content"20                       android:layout_height="wrap_content"21                       android:layout_below="@id/UserName"22                       android:id="@+id/tx_password"23                       android:text="@string/tx_password"/>24         25         <EditText android:layout_width="fill_parent"26                       android:layout_height="wrap_content"27                       android:inputType="textWebPassword"28                       android:background="@android:drawable/editbox_background"29                       android:layout_below="@id/tx_password"30                       android:id="@+id/PassWord"/>31         32         <CheckBox33                 android:id="@+id/Remember_PassWord"34                 android:layout_width="wrap_content"35                 android:layout_height="wrap_content"36                 android:layout_alignParentLeft="true"37                 android:layout_below="@id/PassWord"38                 android:text="@string/tx_remember_password" />39         40         <Button41                 android:id="@+id/Login"42                 android:layout_width="wrap_content"43                 android:layout_height="wrap_content"44                 android:layout_gravity="center_horizontal"45                 android:layout_below="@id/PassWord"46                 android:layout_alignParentRight="true"47                 android:text="@string/tx_login" />48         49 </RelativeLayout>

大概说一下,首先RelativeLayout是相对布局,其中的每个空间都用到了相对布局的标签

1、android:layout_below="@id/tx_username"  意思是:这个控件的顶部,在id为tx_username的下面;

2、android:layout_alignParentLeft="true"  意思是:这个控件,紧贴父控件的右侧;

3、android:padding="10px" 意思是:内边距为10px;

 

 


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击