Android 相對布局


RelativeLayout布局 
android:layout_marginTop="25dip" //頂部距離 
android:gravity="left" //空間布局位置 
android:layout_marginLeft="15dip //距離左邊距 


// 相對於給定ID控件 
android:layout_above 將該控件的底部置於給定ID的控件之上; 
android:layout_below 將該控件的底部置於給定ID的控件之下; 
android:layout_toLeftOf    將該控件的右邊緣與給定ID的控件左邊緣對齊; 
android:layout_toRightOf  將該控件的左邊緣與給定ID的控件右邊緣對齊; 
android:layout_alignBaseline  將該控件的baseline與給定ID的baseline對齊; 
android:layout_alignTop        將該控件的頂部邊緣與給定ID的頂部邊緣對齊; 
android:layout_alignBottom   將該控件的底部邊緣與給定ID的底部邊緣對齊; 
android:layout_alignLeft        將該控件的左邊緣與給定ID的左邊緣對齊; 
android:layout_alignRight      將該控件的右邊緣與給定ID的右邊緣對齊; 

// 相對於父組件 
android:layout_alignParentTop      如果為true,將該控件的頂部與其父控件的頂部對齊; 
android:layout_alignParentBottom 如果為true,將該控件的底部與其父控件的底部對齊; 
android:layout_alignParentLeft      如果為true,將該控件的左部與其父控件的左部對齊; 
android:layout_alignParentRight    如果為true,將該控件的右部與其父控件的右部對齊; 

// 居中 
android:layout_centerHorizontal 如果為true,將該控件的置於水平居中; 
android:layout_centerVertical     如果為true,將該控件的置於垂直居中; 
android:layout_centerInParent   如果為true,將該控件的置於父控件的中央; 

// 指定移動像素 
android:layout_marginTop      上偏移的值; 
android:layout_marginBottom 下偏移的值; 
android:layout_marginLeft   左偏移的值; 

android:layout_marginRight   右偏移的值;




android:id  --- 為控件指定相應的ID 
    android:text --- 指定控件當中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當中的字符串 
    android:grivity --- 指定控件的基本位置,比如說居中,居右等位置 這里指的是控件中的文本位置並不是控件本身。 
    android:textSize --- 指定控件當中字體的大小 
    android:background --- 指定該控件所使用的背景色,RGB命名法 
    android:width --- 指定控件的寬度 
    android:height --- 指定控件的高度 
    android:padding* --- 指定控件的內邊距,也就是說控件當中的內容 
    android:sigleLine --- 如果設置為真的話,則控件的內容在同一行中進行顯示 

下邊是相對布局屬性的說明:RelativeLayout 

       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 如果為真,該控件將被至於垂直方向的中央 
      android:layout_marginLeft此屬性用來設置控件之間的間隙(控件和控件之間和內邊距不同) 
    android:padding="3dip"說明了四邊的內邊距是3dip 
              

TableLayout 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
   android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
    android:stretchColumns="0" 
    ></TableLayout> 

android:stretchColumns="0"第一列作為拉伸列填滿整行 

EditText  屬性說明 


android:scrollHorizontally 
設置文本超出TextView的寬度的情況下,是否出現橫拉條。 


  下面的 更清晰些。---------------------------------------------------- 
第一類:屬性值為true或false 
    android:layout_centerHrizontal  水平居中 
     android:layout_centerVertical   垂直居中 
    android:layout_centerInparent    相對於父元素完全居中 
    android:layout_alignParentBottom 貼緊父元素的下邊緣 
    android:layout_alignParentLeft   貼緊父元素的左邊緣 
    android:layout_alignParentRight  貼緊父元素的右邊緣 
    android:layout_alignParentTop    貼緊父元素的上邊緣 
    android:layout_alignWithParentIfMissing  如果對應的兄弟元素找不到的話就以父元素做參照物 

    第二類:屬性值必須為id的引用名“@id/id-name” 
    android:layout_below      在某元素的下方 
    android:layout_above      在某元素的的上方 
    android:layout_toLeftOf   在某元素的左邊 
    android:layout_toRightOf  在某元素的右邊 

    android:layout_alignTop   本元素的上邊緣和某元素的的上邊緣對齊 
    android:layout_alignLeft  本元素的左邊緣和某元素的的左邊緣對齊 
    android:layout_alignBottom 本元素的下邊緣和某元素的的下邊緣對齊 
    android:layout_alignRight  本元素的右邊緣和某元素的的右邊緣對齊 

    第三類:屬性值為具體的像素值,如30dip,40px 
    android:layout_marginBottom              離某元素底邊緣的距離 
    android:layout_marginLeft                   離某元素左邊緣的距離 
    android:layout_marginRight                 離某元素右邊緣的距離 
    android:layout_marginTop                   離某元素上邊緣的距離 


EditText的android:hint 

設置EditText為空時輸入框內的提示信息。 

android:gravity  
android:gravity屬性是對該view 內容的限定.比如一個button 上面的text.  你可以設置該text 在view的靠左,靠右等位置.以button為例,android:gravity="right"則button上面的文字靠右 

android:layout_gravity 
android:layout_gravity是用來設置該view相對與起父view 的位置.比如一個button 在linearlayout里,你想把該button放在靠左、靠右等位置就可以通過該屬性設置.以button為例,android:layout_gravity="right"則button靠右 

android:layout_alignParentRight 
使當前控件的右端和父控件的右端對齊。這里屬性值只能為true或false,默認false。 


轉自:http://blog.sina.com.cn/s/blog_485c8cc50100u6cw.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM