相对布局(RelativeLayout)的XML

 相对布局的设计一:

<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:orientation="vertical">

<TextView
android:id="@+id/mytext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<EditText
android:id="@+id/myeditbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/mytext"
android:background="@android:drawable/editbox_background" />

<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/myeditbox"
android:layout_marginLeft="12dip"
android:text="@string/sure" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/ok"
android:layout_alignBottom="@id/ok"
android:text="@string/quit" />

</RelativeLayout>

 

 相对布局的设计二:

<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/view01"  

          android:layout_width="wrap_content"     

          android:layout_height="wrap_content"      

          android:layout_centerInParent="true"     

          android:background="@color/blue"   

          android:text="@string/hello_world" />

    <TextView

          android:layout_width="wrap_content"  

          android:layout_height="wrap_content"  

          android:layout_above="@id/view01"   

          android:layout_alignLeft="@id/view01"  

          android:background="@color/red"

          android:text="@string/t1" />

    <TextView   

         android:layout_width="wrap_content"  

          android:layout_height="wrap_content"  

          android:layout_toRightOf="@id/view01"  

          android:background="@color/green"  

          android:text="@string/t3"

        //  android:layout_alignParentRight="true"  相对于父容器右对齐

          android:layout_alignTop="@id/view01"/>

    <TextView  

          android:layout_width="wrap_content"   

          android:layout_height="wrap_content"  

          android:layout_alignLeft="@id/view01"   

          android:layout_below="@id/view01"  

          android:background="@color/red"   

          android:text="@string/t4" />

    <TextView     

          android:layout_width="wrap_content"     

          android:layout_height="wrap_content"   

          android:layout_toLeftOf="@id/view01"     

          android:background="@color/back"     

          android:text="@string/t2"    

         //  android:layout_alignParentLeft="true"  相对于父容器左对齐 

          android:layout_alignTop="@id/view01"/>

</RelativeLayout>

posted on 2014-11-19 20:23  Iitb  阅读(289)  评论(0)    收藏  举报

导航