Android佈局控件之RelativeLayout詳解

Android佈局控件之RelativeLayout詳解

RelativeLayout是相對佈局,相對佈局指的是某個組件的位置是相對於它所以來的組件的位置  

android佈局屬性詳解

RelativeLayout用到的一些重要的屬性:

 

    第一類:屬性值爲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。

android:scaleType:android:scaleType是控制圖片如何resized/moved來匹對ImageView的size。ImageView.ScaleType / android:scaleType值的意義區別:

CENTER /center  按圖片的原來size居中顯示,當圖片長/寬超過View的長/寬,則截取圖片的居中部分顯示

CENTER_CROP / centerCrop 按比例擴大圖片的size居中顯示,使得圖片長(寬)等於或大於View的長(寬)

CENTER_INSIDE / centerInside 將圖片的內容完整居中顯示,通過按比例縮小或原來的size使得圖片長/寬等於或小於View的長/寬

FIT_CENTER / fitCenter 把圖片按比例擴大/縮小到View的寬度,居中顯示

FIT_END / fitEnd   把圖片按比例擴大/縮小到View的寬度,顯示在View的下部分位置

FIT_START / fitStart  把圖片按比例擴大/縮小到View的寬度,顯示在View的上部分位置

FIT_XY / fitXY  把圖片不按比例擴大/縮小到View的大小顯示

MATRIX / matrix 用矩陣來繪製,動態縮小放大圖片來顯示。

** 要注意一點,Drawable文件夾裏面的圖片命名是不能大寫的。

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    <TextView 

    android:layout_width="80px"

    android:layout_height="wrap_content"

    android:textSize="20px"

    android:text="帳號:"

    android:id="@+id/passlable"

    />

   <EditText   

    android:layout_width="200px"

    android:layout_height="wrap_content"

    android:layout_toRightOf="@id/passlable"

    android:layout_alignTop="@id/passlable"

    />

</RelativeLayout>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    <TextView 

    android:layout_width="80px"

    android:layout_height="wrap_content"

    android:textSize="20px"

    android:text="密碼:"

    android:id="@+id/passlable"

    />

   <EditText   

    android:layout_width="200px"

    android:layout_height="wrap_content"

    android:layout_toRightOf="@id/passlable"

    android:layout_alignTop="@id/passlable"

    />

</RelativeLayout>

   

</LinearLayout>

發佈了15 篇原創文章 · 獲贊 32 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章