android:layout_above 将该控件的底部至于给定ID的控件之上
android:layout_below 将该控件的顶部至于给定ID的控件之下
android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐
android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐

android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline(基准线)对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘
android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐
android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐


android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐
android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐
android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐
android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐

android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央
android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央

 1 import android.os.Bundle; 2 import android.widget.Button; 3 import android.app.Activity; 4  5 public class Layout04 extends Activity { 6     private Button ok; 7     private Button cancel; 8     @Override 9     protected void onCreate(Bundle savedInstanceState) {10         super.onCreate(savedInstanceState);11         setContentView(R.layout.main);12         ok = (Button)findViewById(R.id.ok);13         cancel = (Button)findViewById(R.id.cancel);14         15         ok.setText(R.string.Ok);16         cancel.setText(R.string.Cancel);17     }18 }

 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3                 android:layout_width="fill_parent" 4                 android:layout_height="wrap_content" 5                 android:padding="10px" > 6  7     <TextView android:id="@+id/label"  8               android:layout_width="fill_parent"  9               android:layout_height="wrap_content" 10               android:text="Type here:" />11 12     <EditText 13               android:id="@+id/entry" 14               android:layout_width="fill_parent" 15               android:layout_height="wrap_content" 16               android:background="@android:drawable/editbox_background"17               android:layout_below="@id/label" />18   19     <Button android:id="@+id/ok" 20             android:layout_width="wrap_content" 21             android:layout_height="wrap_content" 22             android:layout_below="@id/entry"23             android:layout_alignParentRight="true"24             android:layout_marginLeft="10px"/>25             26     <Button android:id="@+id/cancel"27             android:layout_width="wrap_content" 28             android:layout_height="wrap_content"29             android:layout_toLeftOf="@id/ok"30             android:layout_alignTop="@id/ok"31             />32 </RelativeLayout>

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">Layout04</string>    <string name="action_settings">Settings</string>    <string name="hello_world">Hello world!</string>    <string name="Cancel">Cancel</string>    <string name="Ok">okk</string></resources>

RelativeLayout布局4.2几新特性:
android:layout_alignStart 表示将该控件放置在指定id控件的头部对齐
android:layout_alignEnd 表示将该控件放置在指定id控件的尾部对齐
android:layout_alignParentStart 如果为true,则将该控件放置在父控件的头部
android:layout_alignParentEnd 如果为true,则将该控件放置在父控件的尾部

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <TextView        android:id="@+id/view"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentEnd="true"        android:text="@string/hello_world"         />         <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignEnd="@id/view"        android:layout_below="@id/view"        android:text="hfasdrld"         /></RelativeLayout>

EditText控件的两个属性:

android:hint="password" 设置EditText控件显示的文本
android:inputType="" 设置EditText控件输入的类型

 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     android:paddingBottom="@dimen/activity_vertical_margin" 6     android:paddingLeft="@dimen/activity_horizontal_margin" 7     android:paddingRight="@dimen/activity_horizontal_margin" 8     android:paddingTop="@dimen/activity_vertical_margin" 9     tools:context=".MainActivity" >10 11     <TextView12         android:id="@+id/myTextView"13         android:layout_width="match_parent"14         android:layout_height="wrap_content"15         android:gravity="center"16         android:text="@string/TextView1" />17     18     <EditText19         android:id="@+id/uersname"20         android:layout_width="wrap_content"21         android:layout_height="wrap_content"22         android:layout_alignParentLeft="true"23         android:layout_alignParentRight="true"24         android:layout_below="@id/myTextView"25         android:hint="uersname"26         />27     28     29      <EditText30         android:id="@+id/password"31         android:layout_width="wrap_content"32         android:layout_height="wrap_content"33         android:layout_alignLeft="@id/uersname"34         android:layout_alignRight="@id/uersname"35         android:layout_below="@id/uersname"36         android:hint="password"37         android:inputType="textPassword"38         />39      40      <Button41          android:id="@+id/myButton1"42          android:layout_width="wrap_content"43          android:layout_height="wrap_content"44          android:layout_alignParentRight="true"45          android:layout_below="@id/password"46          android:text="@string/Button1"47          />48 49       <Button50           android:id="@+id/myButton2"51           android:layout_width="wrap_content"52           android:layout_height="wrap_content"53           android:layout_alignBaseline="@+id/myButton1"54           android:layout_alignBottom="@+id/myButton1"55           android:layout_toLeftOf="@+id/myButton1"56           android:text="@string/Button2" />57 58 </RelativeLayout>

更多相关文章

  1. android 所有布局属性和UI控件
  2. UI控件之显示文本控件TextView(上)
  3. Android 学习1----控件的学习
  4. android更换控件默认样式
  5. [整] Android ListView 去除边缘阴影、选中色、拖动背景色等
  6. Android M新控件之FloatingActionButton,TextInputLayout,Snackbar
  7. android自学第二天 Android API Guide学习和LinearLayout布局及
  8. Android 如何自己定义控件的样式 Shape

随机推荐

  1. Android异常捕获防止崩溃弹框
  2. Android――ContentProvider (一)创建conte
  3. Android ClickableRoundedBackground Spa
  4. android 手电筒demo
  5. Android动态改变TextView字体颜色
  6. android Processes and Threads的注意事
  7. android 古怪问题解决集合
  8. Android加密(一)
  9. android 获取IP
  10. Android 使用Dom与SAX解析xml文档的方式