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為空時輸入框內(nèi)的提示信息。
android:gravity android:gravity屬性是對該view內(nèi)容的限定.比如一個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值的意義區(qū)別:
CENTER /center? 按圖片的原來size居中顯示,當圖片長/寬超過View的長/寬,則截取圖片的居中部分顯示
CENTER_CROP / centerCrop 按比例擴大圖片的size居中顯示,使得圖片長(寬)等于或大于View的長(寬)
CENTER_INSIDE / centerInside 將圖片的內(nèi)容完整居中顯示,通過按比例縮小或原來的size使得圖片長/寬等于或小于View的長/寬
FIT_CENTER / fitCenter 把圖片按比例擴大/縮小到View的寬度,居中顯示
FIT_END / fitEnd? 把圖片按比例擴大/縮小到View的寬度,顯示在View的下部分位置
FIT_START / fitStart? 把圖片按比例擴大/縮小到View的寬度,顯示在View的上部分位置
FIT_XY / fitXY? 把圖片不按比例擴大/縮小到View的大小顯示
MATRIX / matrix 用矩陣來繪制,動態(tài)縮小放大圖片來顯示。
** 要注意一點,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>
Android布局控件之RelativeLayout詳解
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內(nèi)容
- Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
- Android功能強大,界面華麗,但是眾多的布局屬性就害苦了開發(fā)者,下面這篇文章結合了網(wǎng)上不少資料.第一類:屬性值...
- 前言:ConstraintLayout是Google在16年Google I/O大會上與AS 2.2預覽版一起發(fā)布...