Android新布局方式ConstraintLayout快速入門教程
前言
在Android開發(fā)中,我們通常是手寫布局,很少會用拖動來寫布局,雖然ConstraintLayout在I/O上以拖動來展現(xiàn)了各種功能,我估計(jì)在以后開發(fā)中,程序員還是習(xí)慣手?jǐn)]代碼。
我自己試著拖著用了一下,用得不是很明白 ,而且用起來效果不是很好。
那么
直接上手?jǐn)]了一下~~~
其實(shí)很簡單
Button1:app:layout_constraintBottom_toTopOf="@id/iv_head"
我們把這個屬性拆開來看,constraintBottom指的本身的底部,即Button1的頂部,toTopOf是指ImageView的頂部,那么這句話的意思就是
Aligns the bottom of the desired view to the top of another.(官方原文)
翻譯一下就是Button1的底部要和ImageView的頂部對齊
Button1 app:layout_constraintRight_toLeftOf="@id/iv_head"
根據(jù)上面的規(guī)則我們就知道Button1的右邊要和ImageView的左邊對齊。
其實(shí)很簡單就是說兩個View的某個方位要對齊
沒了,就這么簡單,其它屬性可以舉一反三,它比RelativeLayout控制起來更加得以就手。
- layout_constraintTop_toTopOf — Align the top of the desired view to the top of another.
- layout_constraintTop_toBottomOf — Align the top of the desired view to the bottom of another.
- layout_constraintBottom_toTopOf — Align the bottom of the desired view to the top of another.
- layout_constraintBottom_toBottomOf — Align the bottom of the desired view to the bottom of another.
- layout_constraintLeft_toTopOf — Align the left of the desired view to the top of another.
- layout_constraintLeft_toBottomOf — Align the left of the desired view to the bottom of another.
- layout_constraintLeft_toLeftOf — Align the left of the desired view to the left of another.
- layout_constraintLeft_toRightOf — Align the left of the desired view to the right of another.
- layout_constraintRight_toTopOf — Align the right of the desired view to the top of another.
- layout_constraintRight_toBottomOf — Align the right of the desired view to the bottom of another.
- layout_constraintRight_toLeftOf — Align the right of the desired view to the left of another.
- layout_constraintRight_toRightOf — Align the right of the desired view to the right of another.
- If desired, attributes supporting start and end are also available in place of left and right alignment.
到此,你已經(jīng)掌握了一大半的ConstraintLayout知識點(diǎn)
還有其它的一些屬性
app:layout_constraintStart_toEndOf
意思就是Button的開始部分(從左往右看,開始部分就是Button的左邊)與ImageView的右邊是對齊的。
app:layout_constraintStart_toStartOf
這個就是說Button的左邊與ImageView的左邊是對齊的
不知道為什么上面已經(jīng)出的屬性能夠滿足布局需要了,為什么還要再出start和end的。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
Android性能優(yōu)化之Bitmap圖片優(yōu)化詳解
在Android項(xiàng)目的imageview中使用大圖bitmap時(shí)會占據(jù)很大的內(nèi)存,而且在很多時(shí)候我們并不需要顯示原圖那么大的圖片, 所以我們需要對圖片進(jìn)行優(yōu)化,這篇文章主要介紹了Android性能優(yōu)化之Bitmap圖片優(yōu)化的相關(guān)資料,需要的朋友們下面來一起看看吧。2017-04-04Android 開發(fā)使用PopupWindow實(shí)現(xiàn)彈出警告框的復(fù)用類示例
這篇文章主要介紹了Android 開發(fā)使用PopupWindow實(shí)現(xiàn)彈出警告框的復(fù)用類,結(jié)合實(shí)例形式分析了Android基于PopupWindow彈出警告框的復(fù)用類具體布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-05-05基于Android FileProvider 屬性配置詳解及FileProvider多節(jié)點(diǎn)問題
這篇文章主要介紹了基于Android FileProvider 屬性配置詳解及FileProvider多節(jié)點(diǎn)問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android實(shí)現(xiàn)自動變換大小的組件ViewPager2
這篇文章主要介紹了Android實(shí)現(xiàn)自動變換大小的組件ViewPager2,ViewPager2最顯著的特點(diǎn)是基于RecyclerView實(shí)現(xiàn),RecyclerView是目前Android端最成熟的AdapterView解決方案2023-03-03Android?Springboot?實(shí)現(xiàn)SSE通信案例詳解
SSE是一種用于實(shí)現(xiàn)服務(wù)器主動向客戶端推送數(shù)據(jù)的技術(shù),它基于?HTTP?協(xié)議,利用了其長連接特性,在客戶端與服務(wù)器之間建立一條持久化連接,并通過這條連接實(shí)現(xiàn)服務(wù)器向客戶端的實(shí)時(shí)數(shù)據(jù)推送,這篇文章主要介紹了Android?Springboot?實(shí)現(xiàn)SSE通信案例,需要的朋友可以參考下2024-07-07詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法
這篇文章主要介紹了詳解Android使用Handler造成內(nèi)存泄露的分析及解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12Android開發(fā)微信小程序路由跳轉(zhuǎn)方式
這篇文章主要為大家介紹了Android開發(fā)微信小程序路由跳轉(zhuǎn)方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04Android Studio 配置:自定義頭部代碼注釋及添加模版方式
這篇文章主要介紹了Android Studio 配置:自定義頭部代碼注釋及添加模版方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android編程根據(jù)系列圖片繪制動畫實(shí)例總結(jié)
這篇文章主要介紹了Android編程根據(jù)系列圖片繪制動畫的方法,以實(shí)例形式總結(jié)了Android根據(jù)圖片繪制動畫的常見情況與具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android自定義VIew實(shí)現(xiàn)衛(wèi)星菜單效果淺析
這篇文章主要介紹了Android自定義VIew實(shí)現(xiàn)衛(wèi)星菜單效果淺析,非常不錯具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11