相對布局(中)

來源:互聯網
上載者:User

標籤:des   android   cWeb   style   class   blog   

1. 對齊至控制項的基準線

2. 與父控制項的四個邊緣對齊

3. 對齊至父控制項的中央

 

1. 對齊至控制項的基準線

   

 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     tools:context="first.pack.MainActivity$PlaceholderFragment" > 6  7     <TextView 8         android:id="@+id/firstView" 9         android:layout_width="wrap_content"10         android:layout_height="wrap_content"11         android:textSize="50sp"12         android:background="#FF0000"13         android:text="hello" />14     15     <TextView16         android:layout_width="wrap_content"17         android:layout_height="wrap_content"18         android:layout_toRightOf="@+id/firstView"19         android:layout_alignBaseline="@+id/firstView"  //對齊基準線!!!20         android:background="#00FF00"21         android:text="mirrorhanyu" />22 23 </RelativeLayout>

 

2. 與父控制項的四個邊緣對齊

      

 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     tools:context="first.pack.MainActivity$PlaceholderFragment" > 6  7     <TextView 8         android:id="@+id/firstView" 9         android:layout_width="wrap_content"10         android:layout_height="wrap_content"11         android:textSize="50sp"12         android:background="#FF0000"13         android:layout_alignParentRight="true"   //與父控制項右邊對齊14         android:text="hello" />  15 16 </RelativeLayout>

    

    

     當代碼為

 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     tools:context="first.pack.MainActivity$PlaceholderFragment" > 6  7     <RelativeLayout     8         android:layout_width="wrap_content" 9         android:layout_height="300dp"10         android:background="#00FF00">11         <TextView12             android:id="@+id/firstView"13             android:layout_width="wrap_content"14             android:layout_height="wrap_content"15             android:textSize="50sp"16             android:background="#FF0000"17             android:layout_alignParentRight="true"   //與就近的父控制項對齊18             android:layout_alignParentBottom="true"19             android:text="hello" />  20     </RelativeLayout>21 </RelativeLayout>

        

 

      

3. 對齊至父控制項的中央

           

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.